本文整理匯總了Java中org.scribe.oauth.OAuthService.signRequest方法的典型用法代碼示例。如果您正苦於以下問題:Java OAuthService.signRequest方法的具體用法?Java OAuthService.signRequest怎麽用?Java OAuthService.signRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.scribe.oauth.OAuthService
的用法示例。
在下文中一共展示了OAuthService.signRequest方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: afterFinalUriConstructed
import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
@Override
protected String afterFinalUriConstructed(HttpRequestBase forMethod, String finalUri, Map<String, ? extends Object> parameters)
{
long start = System.currentTimeMillis();
//
// generate oauth 1.0 params for 2LO - use scribe so far for that ...
//
OAuthService service = createOauthService();
OAuthRequest request = new OAuthRequest(Verb.valueOf(forMethod.getMethod()), finalUri);
addParametersForSigning(request, parameters);
service.signRequest(new EmptyToken(), request);
Map<String, String> oauthParams = request.getOauthParameters();
//
//
log.debug("2LO signing took [{}] ms ", System.currentTimeMillis() - start);
return finalUri + paramsToString(oauthParams, finalUri.indexOf("?") != -1);
}
示例2: onConnectionCreated
import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
@Override
protected void onConnectionCreated(HttpClient client, HttpRequestBase method, Map<String, ? extends Object> parameters)
throws IOException
{
long start = System.currentTimeMillis();
//
// generate oauth 1.0 params for 3LO - use scribe so far for that ...
//
OAuthService service = createOauthService();
OAuthRequest request = new OAuthRequest(Verb.valueOf(method.getMethod()), method.getURI().toString());
addParametersForSigning(request, parameters);
service.signRequest(generateAccessTokenObject(accessTokenWithSecret), request);
String header = authHeaderCreator.extract(request);
method.addHeader(OAuthConstants.HEADER, header);
log.debug("3LO signing took [{}] ms ", System.currentTimeMillis() - start);
}
示例3: getUserInfoJSON
import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
private JSONObject getUserInfoJSON(String code, String callBackUrl) {
OAuthService service = new ServiceBuilder()
.provider(FacebookApi.class)
.apiKey(apiKey)
.apiSecret(apiSecret)
.callback(host + callBackUrl)
.scope("email")
.build();
Verifier verifier = new Verifier(code);
Token accessToken = service.getAccessToken(NULL_TOKEN, verifier);
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
request.addOAuthParameter("scope", "email");
service.signRequest(accessToken, request);
Response response = request.send();
LOG.info("response body is " + response.getBody());
try {
JSONObject obj = new JSONObject(response.getBody());
obj.put("access_token", accessToken.getToken());
return obj;
} catch (JSONException e) {
return new JSONObject();
}
}
示例4: getSocialUser
import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
private SocialUser getSocialUser(Token accessToken,int authProvider) throws OurException
{
logger.info("Token: " + accessToken + " Provider: " + authProvider);
OAuthService service = getOAuthService(authProvider);
String url = getProtectedResourceUrlFromSession();
logger.info("protected url: " + url);
OAuthRequest request = new OAuthRequest(Verb.GET,url);
// sign the request
service.signRequest(accessToken,request);
Response response = request.send();
String json = response.getBody();
SocialUser socialUser = getSocialUserFromJson(json,authProvider);
return socialUser;
}
示例5: send
import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
public E send(OAuthService oAuthService, Token accessToken) {
OAuthRequest request = getRequest();
oAuthService.signRequest(accessToken, request);
Response response = null;
long tsStart = System.currentTimeMillis();
try {
System.out.println("[REQUEST] " + request.getVerb() + " "
+ request.getCompleteUrl());
response = request.send();
System.out.println("> " + response.getBody());
} finally {
long tsEnd = System.currentTimeMillis();
System.out.println("[REQUEST] SC=" + response.getCode() + " in "
+ (tsEnd - tsStart) + "ms <- " + request.getVerb() + " "
+ request.getCompleteUrl());
}
soupErrorHandler.handle(request, response);
return convertResponse(response);
}
示例6: retrieveEntitySample1
import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
public SampleEntity retrieveEntitySample1(Token accessToken) throws ClientException
{
OAuthService service = getOAuthService(scopes, null);
OAuthRequest request = new OAuthRequest(Verb.GET,
"http://localhost:9998/testsuite/rest/sample/1");
service.signRequest(accessToken, request);
Response response = request.send();
if (response.getCode()!=200)
throwClientException(response);
ObjectMapper mapper = new ObjectMapper();
try {
SampleEntity entity = mapper.readValue(response.getBody(), SampleEntity.class);
return entity;
} catch (IOException e) {
throw new ClientException(response.getBody());
}
}
示例7: getUserBlogs
import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
public static List<String> getUserBlogs(Token accToken) throws IOException {
String userInformationUrl = "http://api.tumblr.com/v2/user/info";
OAuthService service = new ServiceBuilder().apiKey(consumer_key).apiSecret(secret_key).provider(TumblrApi.class).build();
OAuthRequest request = new OAuthRequest(Verb.GET, userInformationUrl);
service.signRequest(accToken, request);
Response response = request.send();
ObjectMapper mapper = new ObjectMapper();
JsonNode jBlogs = mapper.readTree(response.getBody()).get("response").get("user").get("blogs");
List<String> blogs = new ArrayList<>();
for (JsonNode jBlog : jBlogs) {
blogs.add(jBlog.get("name").toString());
}
return blogs;
}
示例8: postRecipe
import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
public static String postRecipe(Token accToken, String recipeName, String host) throws UnsupportedEncodingException {
OAuthService service = new ServiceBuilder().apiKey(consumer_key).apiSecret(secret_key).provider(TumblrApi.class).build();
String url = String.format(POST_URL, host);
OAuthRequest request = new OAuthRequest(Verb.POST, url);
StringBuffer sb = new StringBuffer();
sb.append("de.anycook, recipe");
// for(String tag : recipe.tags){
// sb.append(", ").append(tag);
// }
String photourl = String.format("api.anycook.de/recipe/%s/image?type=large", URLEncoder.encode(recipeName, "UTF-8"));
request.addBodyParameter("type", "photo");
request.addBodyParameter("link", "http://de.anycook.de/#!/recipe/" + URLEncoder.encode(recipeName, "UTF-8"));
request.addBodyParameter("source", photourl);
request.addBodyParameter("tags", sb.toString());
request.addBodyParameter("slug", "via de.anycook.de");
service.signRequest(accToken, request);
return request.send().getBody();
}
示例9: getAttributeProfile
import org.scribe.oauth.OAuthService; //導入方法依賴的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();
}
示例10: execute
import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
private void execute(String payment) {
final OAuthRequest request = new OAuthRequest(Verb.POST, getString(R.string.payment));
request.addBodyParameter("category_id", "101");
request.addBodyParameter("genre_id", "10101");
request.addBodyParameter("amount", payment);
String date = DateFormat.format("'yyyy'-'MM'-'dd'", Calendar.getInstance()).toString();
request.addBodyParameter("date", date);
request.addBodyParameter("from_account_id", "1");
final Token accessToken = ZaimUtils.getAccessToken(getApplicationContext());
final OAuthService service = ZaimUtils.getOauthService(getApplicationContext());
service.signRequest(accessToken, request);
request.send();
}
示例11: doAccessAuth
import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
private TwitterAuthDoneEvent doAccessAuth( Token requestToken, String oauthVerifier )
{
Token accessToken = null;
String userName = null;
try
{
OAuthService service = new ServiceBuilder()
.provider( TwitterApi.SSL.class )
.callback( TwitterLoginActivity.TWITTER_CALLBACK_URL )
.apiKey( TwitterConfig.TWITTER_OAUTH_CONSUMER_KEY )
.apiSecret( TwitterConfig.TWITTER_OAUTH_CONSUMER_SECRET )
.build();
accessToken = service.getAccessToken( requestToken, new Verifier( oauthVerifier ) );
// Once we have the access token, we do a quick and dirty request to get the username
OAuthRequest request = new OAuthRequest( Verb.GET, TWITTER_USERNAME_URL );
service.signRequest( accessToken, request );
Response response = request.send();
userName = Helper.extractJsonStringField( response.getBody(), "name" );
}
catch ( Exception e )
{
Helper.debug( "Error while obtaining twitter access token : " + e.getMessage() );
}
boolean success = null != accessToken;
return new TwitterAuthDoneEvent( success, accessToken, userName, null, AuthType.ACCESS );
}
示例12: doAuth
import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
@Override
protected void doAuth( Intent intent )
{
final String code = intent.getStringExtra( SitesLoginHandler.VERIFIER_KEY );
Token accessToken = null;
String userName = null;
try
{
OAuthService service = new ServiceBuilder()
.callback( FacebookLoginActivity.FACEBOOK_CALLBACK_URL )
.provider( FacebookApi.class )
.apiKey( FacebookConfig.FACEBOOK_OAUTH_APP_ID )
.apiSecret( FacebookConfig.FACEBOOK_OAUTH_APP_SECRET )
.build();
accessToken = service.getAccessToken( null, new Verifier( code ) );
OAuthRequest request = new OAuthRequest( Verb.GET, FACEBOOK_USERNAME_URL );
service.signRequest( accessToken, request );
Response response = request.send();
userName = Helper.extractJsonStringField( response.getBody(), "name" );
}
catch ( Exception e )
{
Helper.debug( "Failed to get Facebook access token : " + e.getMessage() );
}
boolean success = null != accessToken;
// Subscriber : FacebookLoginHandler : onFacebookAuthDone()
HashtaggerApp.bus.post( new FacebookAuthDoneEvent( success, accessToken, userName ) );
}
示例13: doAuth
import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
@Override
protected void doAuth( Intent authIntent )
{
final String code = authIntent.getStringExtra( SitesLoginHandler.VERIFIER_KEY );
Token accessToken = null;
String userName = null;
try
{
OAuthService service = new ServiceBuilder()
.provider( Google2Api.class )
.callback( GPlusLoginActivity.GPLUS_CALLBACK_URL )
.apiKey( GPlusConfig.GPLUS_OAUTH_CLIENT_ID )
.apiSecret( GPlusConfig.GPLUS_OAUTH_CLIENT_SECRET )
.scope( GPlusConfig.GPLUS_ACCESS_SCOPE )
.build();
accessToken = service.getAccessToken( null, new Verifier( code ) );
OAuthRequest request = new OAuthRequest( Verb.GET, GPLUS_USERNAME_URL );
service.signRequest( accessToken, request );
Response response = request.send();
userName = Helper.extractJsonStringField( response.getBody(), "displayName" );
}
catch ( Exception e )
{
Helper.debug( "Error while obtaining Google+ access token : " + e.getMessage() );
}
boolean success = null != accessToken;
// Subscriber : GPlusLoginHandler : onGPlusAuthDone()
HashtaggerApp.bus.post( new GPlusAuthDoneEvent( success, accessToken, userName ) );
}
示例14: authorize
import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
@Test
@Ignore("Not suitable as automatic unit test. Requires manual action.")
public void authorize() throws URISyntaxException, IOException {
final String key = System.getProperty("key");
final String secret = System.getProperty("secret");
assertNotNull("You must use a discogs key via System property -Dkey=", key);
assertNotNull("You must use a discogs secret via System property -Dsecret=", secret);
assertNotNull("You must use a custom user agent via System property -Dhttp.agent=", System.getProperty("http.agent"));
final OAuthService service = new ServiceBuilder()
.provider(DiscogsApi.class)
.apiKey(key)
.apiSecret(secret)
.debug()
.build();
final Token requestToken = service.getRequestToken();
System.out.println("Token: " + requestToken);
final String authorizationUrl = service.getAuthorizationUrl(requestToken);
System.out.println("AuthorizationUrl: " + authorizationUrl);
Desktop.getDesktop().browse(new URI(authorizationUrl));
System.out.println("Please enter token: ");
final String token = System.console().readLine();
System.out.println("Got " + token);
final Verifier verifier = new Verifier(token);
// Trade the Request Token and Verifier for the Access Token
final Token accessToken = service.getAccessToken(requestToken, verifier);
final OAuthRequest request = new OAuthRequest(Verb.GET, "https://api.discogs.com/image/R-944131-1175701834.jpeg");
service.signRequest(accessToken, request);
final Response response = request.send();
System.out.println(response.getCode() + " " + response.getMessage());
}
示例15: logActivity
import org.scribe.oauth.OAuthService; //導入方法依賴的package包/類
public void logActivity(long start_time, long duration, float distance, float calories) throws Exception
{
log.info("Recroding: duration=" + duration / 1000l + "s, avg. distance=" + distance + "MPH, calories="
+ calories);
if(token == null)
throw new Exception("Must log in first to log activity");
OAuthService service = new ServiceBuilder().provider(FitbitApi.class).apiKey(fITBIT_API_KEY).apiSecret(FITBIT_API_SECRET)
.build();
Date date = new Date(start_time);
double roundedDist = BigDecimal.valueOf(distance / 1000).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
OAuthRequest request = new OAuthRequest(Verb.POST, ACTIVITY_ADD_URL);
request.addQuerystringParameter("activityName", ACTIVITY_NAME);
request.addQuerystringParameter("manualCalories", "" + Math.round(calories));
request.addQuerystringParameter("startTime", TIME_FORMAT.format(date));
request.addQuerystringParameter("durationMillis", "" + duration);
request.addQuerystringParameter("distance", "" + roundedDist);
request.addQuerystringParameter("date", DATE_FORMAT.format(date));
service.signRequest(token, request);
Response response = request.send();
if(!response.isSuccessful())
{
log.log(Level.SEVERE, "FitBit API Error: " + response.getMessage());
log.fine(response.getBody());
throw new Exception("FitBit API Error: " + response.getMessage());
}
}