本文整理汇总了Java中org.scribe.model.OAuthRequest.send方法的典型用法代码示例。如果您正苦于以下问题:Java OAuthRequest.send方法的具体用法?Java OAuthRequest.send怎么用?Java OAuthRequest.send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.scribe.model.OAuthRequest
的用法示例。
在下文中一共展示了OAuthRequest.send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: send
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
private String send(Verb verb, String params) throws Exception {
String url = apiUrl + ((params != null) ? params : "");
OAuthRequest request = new OAuthRequest(verb, url);
request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, apiAccessToken);
// For more details on the “Bearer” token refer to http://tools.ietf.org/html/draft-ietf-oauth-v2-bearer-23
StringBuilder sb = new StringBuilder();
sb.append("Bearer ");
sb.append(apiAccessToken);
request.addHeader("Authorization", sb.toString());
if (LOG.isDebugEnabled()) {
LOG.debug("Yammer request url: {}", request.getCompleteUrl());
}
Response response = request.send();
if (response.isSuccessful()) {
return response.getBody();
} else {
throw new Exception(String.format("Failed to poll %s. Got response code %s and body: %s", getApiUrl(), response.getCode(), response.getBody()));
}
}
示例2: getAccessToken
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
@Override
public Token getAccessToken(Token requestToken, Verifier verifier) {
OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
switch (api.getAccessTokenVerb()) {
case POST:
request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
request.addBodyParameter(GRANT_TYPE, GRANT_TYPE_AUTHORIZATION_CODE);
break;
case GET:
default:
request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue());
request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
if(config.hasScope()) request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope());
}
Response response = request.send();
return api.getAccessTokenExtractor().extract(response.getBody());
}
示例3: editScript
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
/**
* 编辑指定脚本
*
* @param scriptId
* 脚本ID
* @param description
* 脚本描述
* @param scriptText
* 脚本内容
* @return
* @throws Fit2CloudException
*/
public boolean editScript(long scriptId, String description, String scriptText) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/script/" + scriptId + "/update");
request.addBodyParameter("description", description);
request.addBodyParameter("scriptText", scriptText);
request.setCharset("UTF-8");
Token accessToken = new Token("", "");
service.signRequest(accessToken, request);
Response response = request.send();
int code = response.getCode();
String responseString = response.getBody();
if (code == 200) {
return "true".equals(responseString);
} else {
throw new Fit2CloudException(response.getBody());
}
}
示例4: sampleTwitter
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
private int sampleTwitter(Token accessToken) {
OAuthRequest request = new OAuthRequest(Verb.GET, MENTION_URL);
OAUTH_SERVICE.signRequest(accessToken, request); // the access token
// from step
// 4
Response response = request.send();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
Document doc = factory.newDocumentBuilder().parse(
response.getBody());
NodeList mentions = doc.getElementsByTagName("status");
return mentions.getLength();
} catch (Exception e) {
return -1;
}
}
示例5: changeClusterAndRole
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
public boolean changeClusterAndRole(Long cmdbServerId, String clusterName, String clusterRoleName, String sshIp,
Long sshPort, String sshUser, String sshPwd, String osType) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/cmdbserver/changeClusterAndRole");
request.addBodyParameter("cmdbServerId", String.valueOf(cmdbServerId));
request.addBodyParameter("clusterName", clusterName);
request.addBodyParameter("clusterRoleName", clusterRoleName);
request.addBodyParameter("sshIp", sshIp);
request.addBodyParameter("sshPort", String.valueOf(sshPort));
request.addBodyParameter("sshUser", sshUser);
request.addBodyParameter("sshPwd", sshPwd);
request.addBodyParameter("osType", osType);
request.setCharset("UTF-8");
Token accessToken = new Token("", "");
service.signRequest(accessToken, request);
Response response = request.send();
int code = response.getCode();
System.out.println(code);
if (code == 200) {
return true;
} else {
return false;
}
}
示例6: getSupportedServerMetrics
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
/**
* 获取指定主机组下的所有监控项
*
* @param clusterRoleId
* 主机组ID
* @return
* @throws Fit2CloudException
*/
public List<KeyPair> getSupportedServerMetrics(Long clusterRoleId) throws Fit2CloudException {
if (clusterRoleId == null || clusterRoleId <= 0) {
throw new Fit2CloudException("请检查clusterRoleId的输入!");
}
OAuthRequest request = new OAuthRequest(Verb.GET, restApiEndpoint + "/metrics?clusterRoleId=" + clusterRoleId);
request.setCharset("UTF-8");
Token accessToken = new Token("", "");
service.signRequest(accessToken, request);
Response response = request.send();
int code = response.getCode();
String responseString = response.getBody();
if (code == 200) {
Type listType = new TypeToken<List<KeyPair>>() {
}.getType();
return new GsonBuilder().create().fromJson(responseString, listType);
} else {
throw new Fit2CloudException(responseString);
}
}
示例7: saveTag
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
/**
* 给指定虚机设置标签. 若无则新增标签; 若有则替换
*
* @param serverId
* 虚机ID
* @param tagName
* 标签名称
* @param tagValue
* 标签值
* @return
* @throws Fit2CloudException
*/
public Tag saveTag(Long serverId, String tagName, String tagValue) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/tags/save");
if (serverId != null && serverId.intValue() > 0) {
request.addBodyParameter("serverId", String.valueOf(serverId));
}
if (tagName != null && tagName.trim().length() > 0) {
request.addBodyParameter("tagName", tagName.trim());
}
if (tagValue != null && tagValue.trim().length() > 0) {
request.addBodyParameter("tagValue", tagValue.trim());
}
request.setCharset("UTF-8");
Token accessToken = new Token("", "");
service.signRequest(accessToken, request);
Response response = request.send();
int code = response.getCode();
String responseString = response.getBody();
if (code == 200) {
return new GsonBuilder().create().fromJson(responseString, Tag.class);
} else {
throw new Fit2CloudException(response.getBody());
}
}
示例8: getAccessToken
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
/**
* 获取account_token的http请求参数添加
*/
@Override
public Token getAccessToken(final Token requestToken, final Verifier verifier) {
final OAuthRequest request = new ProxyOAuthRequest(this.api.getAccessTokenVerb(),
this.api.getAccessTokenEndpoint(), this.connectTimeout,
this.readTimeout, this.proxyHost, this.proxyPort);
request.addBodyParameter("appid", this.config.getApiKey());
request.addBodyParameter("secret", this.config.getApiSecret());
request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
request.addBodyParameter(OAuthConstants.REDIRECT_URI, this.config.getCallback());
request.addBodyParameter("grant_type", "authorization_code");
final Response response = request.send();
return this.api.getAccessTokenExtractor().extract(response.getBody());
}
示例9: updateClusterRole
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
public boolean updateClusterRole(Long clusterRoleId, String clusterRoleName) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.POST, restApiEndpoint + "/cmdbserver/updateClusterRole");
request.addBodyParameter("clusterRoleId", String.valueOf(clusterRoleId));
request.addBodyParameter("clusterRoleName", clusterRoleName);
request.setCharset("UTF-8");
Token accessToken = new Token("", "");
service.signRequest(accessToken, request);
Response response = request.send();
int code = response.getCode();
if (code == 200) {
return true;
} else {
return false;
}
}
示例10: doInBackground
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
@Override
protected Void doInBackground(String... params) {
System.out.println("001 OauthEnd doInBackground-->" + params[0]);
String url = params[0];
if (url.contains("user_refused")) {
setResult(RESULT_CANCELED);
finish();
} else {
final Uri uri = Uri.parse(url);
final String verifier = uri.getQueryParameter("oauth_verifier");
final Verifier v = new Verifier(verifier);
System.out.println("hp Verifier>>>> " + v.getValue());
final Token accessToken = oas_linkedin.getAccessToken(requestToken,
v);
final OAuthRequest request = new OAuthRequest(Verb.GET,
PROTECTED_RESOURCE_URL);
oas_linkedin.signRequest(accessToken, request);
Response response = request.send();
// TODO JSON response in intent RESPONSE
Intent intent = new Intent();
intent.putExtra("RESPONSE", response.getBody());
setResult(RESULT_OK, intent);
finish();
}
return null;
}
示例11: getAttributeProfile
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
@Override
public Response getAttributeProfile(long customerId, int clientId, String attribute) {
if (!IdPool.clientInList(customerId, clientId)) {
clientNotFoundMsg.setCustomerId(customerId);
clientNotFoundMsg.setClientId(clientId);
return Response.status(Response.Status.OK).entity(clientNotFoundMsg).type(MediaType.APPLICATION_JSON_TYPE).build();
}
customer = LinkedInCustomerResource.getCustomerList().get(customerId);
client = customer.getClientDB().getClientList().get(clientId);
if (client.getStatus() == linkStatusOff) {
notLinkedMsg = new NotLinked();
notLinkedMsg.setCustomerId(customerId);
notLinkedMsg.setClientId(clientId);
return Response.status(Response.Status.OK).entity(notLinkedMsg).type(MediaType.APPLICATION_JSON_TYPE).build();
}
OAuthRequest request = new OAuthRequest(Verb.GET, LinkedInAppResource.API_BASIC_PROFILE_URI + ":(" + attribute + ")");
request.addHeader("x-li-format", "json");
OAuthService service = client.getLinkHandler().getServiceProvider();
service.signRequest(client.getLinkHandler().getAccessToken(), request);
org.scribe.model.Response response = request.send();
return Response.status(Response.Status.OK).entity(response.getBody()).build();
}
示例12: getCluster
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
/**
* 获取指定集群信息
*
* @param clusterId
* 集群ID
* @return
* @throws Fit2CloudException
*/
public Cluster getCluster(long clusterId) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.GET, restApiEndpoint + "/cluster/" + clusterId);
Token accessToken = new Token("", "");
service.signRequest(accessToken, request);
Response response = request.send();
int code = response.getCode();
String responseString = response.getBody();
if (code == 200) {
return new GsonBuilder().create().fromJson(responseString, Cluster.class);
} else {
throw new Fit2CloudException(responseString);
}
}
示例13: getClusterRole
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
/**
* 获取指定虚机组信息
*
* @param clusterRoleId
* 虚机组ID
* @return
* @throws Fit2CloudException
*/
public ClusterRole getClusterRole(long clusterRoleId) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.GET, restApiEndpoint + "/clusterrole/" + clusterRoleId);
Token accessToken = new Token("", "");
service.signRequest(accessToken, request);
Response response = request.send();
int code = response.getCode();
String responseString = response.getBody();
if (code == 200) {
return new GsonBuilder().create().fromJson(responseString, ClusterRole.class);
} else {
throw new Fit2CloudException(responseString);
}
}
示例14: getScript
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
/**
* 获取指定脚本信息
*
* @param scriptId
* 脚本ID
* @return
* @throws Fit2CloudException
*/
public Script getScript(long scriptId) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.GET, restApiEndpoint + "/script/" + scriptId);
Token accessToken = new Token("", "");
service.signRequest(accessToken, request);
Response response = request.send();
int code = response.getCode();
String responseString = response.getBody();
if (code == 200) {
return new GsonBuilder().create().fromJson(responseString, Script.class);
} else {
throw new Fit2CloudException(responseString);
}
}
示例15: getServer
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
/**
* 获取指定虚机信息
*
* @param serverId
* 虚机ID
* @return
* @throws Fit2CloudException
*/
public Server getServer(long serverId) throws Fit2CloudException {
OAuthRequest request = new OAuthRequest(Verb.GET, restApiEndpoint + "/server/" + serverId);
Token accessToken = new Token("", "");
service.signRequest(accessToken, request);
Response response = request.send();
int code = response.getCode();
String responseString = response.getBody();
if (code == 200) {
return new GsonBuilder().create().fromJson(responseString, Server.class);
} else {
throw new Fit2CloudException(responseString);
}
}