本文整理匯總了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);
}
}