質問

I want to fetch contacts from gmail. for this I am using Sribe using GoogleExample.java Which is working properly and giving me token. For authorization it is giving me link like https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=**

I am doing connection process successfully with google,

1) I want to fetch users contact from his account I am not getting it how to do it. Please provide any example

2) for authorization i have to manually copy link i dont want to do it manually.

Using struts2 for developing this project.

役に立ちましたか?

解決

You do not need to do authorization manually,in scribe this has been done for demo purpose and you have way to do this.

follow below mention steps

  1. Create a Controller which create a request to Google API, you need to pass api_key,secret and can pass redirect_url with other information.
  2. Redirect user to Google and let him/her authorize your application

redirect URL tell any OAuth/OpenID provider where to redirect user back once he/she authorize/reject your application

on redirection back, Google will provide you a authorization token.you can than connect to the Google API to fetch user contacts

this is a demo code how you can fetch data from Google once user redirect back to your site

Verifier verifier = new Verifier(oauth_verifier);
Token accessToken = oAuthGetAccessToken.getAccessToken((Token) session.get(OAuthConstants.REQUEST_TOKEN), verifier, service);
service.signRequest(accessToken, request);
Response response = request.send();

What actually is happening, we created a verifier with the help of verifier token send by Google when user redirected back,we got access_token from the Google internally which work as a key to access user data and finally we sent request to Google API to fetch data.

Please be sure to set the scope in your initial request which tell service provider what all data you want to access from the user profile.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top