本文整理汇总了Java中org.scribe.model.OAuthRequest.addQuerystringParameter方法的典型用法代码示例。如果您正苦于以下问题:Java OAuthRequest.addQuerystringParameter方法的具体用法?Java OAuthRequest.addQuerystringParameter怎么用?Java OAuthRequest.addQuerystringParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.scribe.model.OAuthRequest
的用法示例。
在下文中一共展示了OAuthRequest.addQuerystringParameter方法的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: appendSignature
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
private void appendSignature(OAuthRequest request)
{
switch (config.getSignatureType())
{
case Header:
config.log("using Http Header signature");
String oauthHeader = api.getHeaderExtractor().extract(request);
request.addHeader(OAuthConstants.HEADER, oauthHeader);
break;
case QueryString:
config.log("using Querystring signature");
for (Map.Entry<String, String> entry : request.getOauthParameters().entrySet())
{
request.addQuerystringParameter(entry.getKey(), entry.getValue());
}
break;
}
}
示例3: 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());
}
示例4: appendSignature
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
private void appendSignature(OAuthRequest request)
{
switch (config.getSignatureType())
{
case Header:
config.log("using Http Header signature");
String oauthHeader = api.getHeaderExtractor().extract(request);
request.addHeader(OAuthConstants.HEADER, oauthHeader);
break;
case QueryString:
config.log("using Querystring signature");
for (Map.Entry<String, String> entry : request.getOauthParameters().entrySet())
{
request.addQuerystringParameter(entry.getKey(), entry.getValue());
}
break;
}
}
示例5: getAuthorizationUrl
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
@Override
public String getAuthorizationUrl(OAuthConfig config, String state) {
// http://wiki.connect.qq.com/%E4%BD%BF%E7%94%A8authorization_code%E8%8E%B7%E5%8F%96access_token
final String authorizationEndpoint = "https://graph.qq.com/oauth2.0/authorize";
OAuthRequest request = new OAuthRequest(Verb.GET, authorizationEndpoint);
request.addQuerystringParameter("response_type", "code");
request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
request.addQuerystringParameter("state", state);
if (config.hasScope()) {
request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope());
}
return request.getCompleteUrl();
}
示例6: signRequest
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
@Override
public void signRequest(final Token accessToken, final OAuthRequest request) {
request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
String response = accessToken.getRawResponse();
Matcher matcher = openIdPattern.matcher(response);
if (matcher.find()) {
request.addQuerystringParameter("openid", matcher.group(1));
} else {
throw new OAuthException("微信接口返回数据miss openid: " + response);
}
}
示例7: signRequest
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
@Override
public void signRequest(Token accessToken, OAuthRequest request) {
switch (config.getSignatureType()) {
case Header:
config.log("using Http Header signature");
request.addHeader(OAuthConstants.HEADER, bearerName + " " + accessToken.getToken());
break;
case QueryString:
config.log("using Querystring signature");
request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
break;
}
}
示例8: getAccessToken
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
@Override
public Token getAccessToken(Token requestToken, Verifier verifier) {
OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
request.addQuerystringParameter("grant_type", "authorization_code");
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());
}
示例9: addUrlParams
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
private void addUrlParams(OAuthRequest request, Map.Entry<String, String>... params) {
for (Map.Entry<String, String> pair : params) {
if (pair != null) {
request.addQuerystringParameter(pair.getKey(), pair.getValue());
}
}
}
示例10: searchByBusinessId
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
/**
* Creates and sends a request to the Business API by business ID with additional params.
* <p>
* See <a href="http://www.yelp.com/developers/documentation/v2/business">Yelp Business API V2</a>
* for more info.
*
* @param businessID <tt>String</tt> business ID of the requested business
* @param searchRequest SearchRequest pojo used to provide parameters
* @return <tt>String</tt> JSON Response
*/
public Business searchByBusinessId(String businessID, SearchRequest searchRequest) {
OAuthRequest request = createOAuthRequest(BUSINESS_PATH + "/" + businessID);
if (searchRequest.getCountryCode() != null) {
request.addQuerystringParameter("cc", searchRequest.getCountryCode());
}
if (searchRequest.getLanguage() != null) {
request.addQuerystringParameter("lang", searchRequest.getLanguage());
}
if (searchRequest.getActionLinks() != null) {
request.addQuerystringParameter("actionlinks", searchRequest.getActionLinks().toString());
}
return sendRequestAndGetResponse(request, Business.class);
}
示例11: signRequest
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
@Override
public void signRequest(Token token, OAuthRequest request) {
request.addQuerystringParameter(ACCESS_TOKEN, token.getToken());
}
示例12: getUserInfo
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
@Override
public OAuthUserInfo getUserInfo(OAuthToken token) throws IOException {
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
Token t = new Token(token.getToken(), token.getSecret(), token.getRaw());
request.addQuerystringParameter(FIELDS_QUERY, FIELDS);
service.signRequest(t, request);
Response response = request.send();
if (response.getCode() != HttpServletResponse.SC_OK) {
throw new IOException(
String.format(
"Status %s (%s) for request %s",
response.getCode(), response.getBody(), request.getUrl()));
}
JsonElement userJson =
OutputFormat.JSON.newGson().fromJson(response.getBody(), JsonElement.class);
if (log.isDebugEnabled()) {
log.debug("User info response: {}", response.getBody());
}
if (userJson.isJsonObject()) {
JsonObject jsonObject = userJson.getAsJsonObject();
JsonElement id = jsonObject.get("id");
if (id == null || id.isJsonNull()) {
throw new IOException(String.format("Response doesn't contain id field"));
}
JsonElement email = jsonObject.get("email");
JsonElement name = jsonObject.get("name");
// Heads up!
// Lets keep `login` equal to `email`, since `username` field is
// deprecated for Facebook API versions v2.0 and higher
JsonElement login = jsonObject.get("email");
return new OAuthUserInfo(
FACEBOOK_PROVIDER_PREFIX + id.getAsString(),
login == null || login.isJsonNull() ? null : login.getAsString(),
email == null || email.isJsonNull() ? null : email.getAsString(),
name == null || name.isJsonNull() ? null : name.getAsString(),
null);
}
throw new IOException(String.format("Invalid JSON '%s': not a JSON Object", userJson));
}
示例13: signRequest
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
@Override
public void signRequest(Token accessToken, OAuthRequest request) {
request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
}
示例14: getProfileUrl
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
protected String getProfileUrl(Token accessToken) {
OAuthRequest request = new OAuthRequest(Verb.GET, OPEN_ID_URL);
request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
return request.getCompleteUrl();
}
示例15: searchForBusinessesByLocation
import org.scribe.model.OAuthRequest; //导入方法依赖的package包/类
/**
* Creates and sends a request to the Search API by term and location.
* <p>
* See <a href="http://www.yelp.com/developers/documentation/v2/search_api">Yelp Search API V2</a>
* for more info.
*
* @param searchRequest pojo containing search parameters
* @return <tt>String</tt> JSON Response
*/
public SearchResult searchForBusinessesByLocation(SearchRequest searchRequest) {
OAuthRequest request = createOAuthRequest(SEARCH_PATH);
if (searchRequest.getTerm() != null) {
request.addQuerystringParameter("term", searchRequest.getTerm());
}
if (searchRequest.getLimit() != null) {
request.addQuerystringParameter("limit", searchRequest.getLimit().toString());
}
if (searchRequest.getOffset() != null) {
request.addQuerystringParameter("offset", searchRequest.getOffset().toString());
}
if (searchRequest.getSort() != null) {
request.addQuerystringParameter("sort", searchRequest.getSort().id().toString());
}
if (searchRequest.getCategoryFilter() != null) {
request.addQuerystringParameter("category_filter", searchRequest.getCategoryFilter());
}
if (searchRequest.getRadiusFilter() != null) {
request.addQuerystringParameter("radius_filter", searchRequest.getRadiusFilter().toString());
}
if (searchRequest.getDealsFilter() != null) {
request.addQuerystringParameter("deals_filter", searchRequest.getDealsFilter().toString());
}
if (searchRequest.getLocation() != null) {
request.addQuerystringParameter("location", searchRequest.getLocation());
if (searchRequest.getLatitude() != null && searchRequest.getLongitude() != null) {
String cll = searchRequest.getLatitude() + "," + searchRequest.getLongitude();
request.addQuerystringParameter("cll", cll);
}
}
if (searchRequest.getSwLatitude() != null && searchRequest.getSwLongitude() != null
&& searchRequest.getNeLatitude() != null && searchRequest.getNeLongitude() != null) {
String bounds = searchRequest.getSwLatitude() + "," +
searchRequest.getSwLongitude() + "|" +
searchRequest.getNeLatitude() + "," +
searchRequest.getNeLongitude();
request.addQuerystringParameter("bounds", bounds);
}
if (searchRequest.getLanguage() == null && searchRequest.getLatitude() != null
&& searchRequest.getLongitude() != null) {
String ll = searchRequest.getLatitude() + "," +
searchRequest.getLongitude() + "," +
searchRequest.getAccuracy() + "," +
searchRequest.getAltitude() + "," +
searchRequest.getAltitudeAccuracy();
request.addQuerystringParameter("ll", ll);
}
if (searchRequest.getCountryCode() != null) {
request.addQuerystringParameter("cc", searchRequest.getCountryCode());
}
if (searchRequest.getLanguage() != null) {
request.addQuerystringParameter("lang", searchRequest.getLanguage());
}
if (searchRequest.getActionLinks() != null) {
request.addQuerystringParameter("actionlinks", searchRequest.getActionLinks().toString());
}
return sendRequestAndGetResponse(request, SearchResult.class);
}