0

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.

xrcwrn
  • 5,339
  • 17
  • 68
  • 129

1 Answers1

1

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.

Umesh Awasthi
  • 23,407
  • 37
  • 132
  • 204
  • i got little bit. I want to fully understand it from where can i get Examples. – xrcwrn Nov 28 '12 at 05:27
  • @Manish Scribe provide fully example and all you need to modify it to your web-application – Umesh Awasthi Nov 28 '12 at 05:29
  • @Umesh Awasthi, I tried to follow the LinkedIn example. It doesn't have a REDIRECT_URL, when the code reached this part: `Verifier verifier = new Verifier(in.nextLine());` what should I input? Tks – EyeQ Tech Apr 28 '13 at 06:39
  • @TungMaiLe:this is example for desktop application, you need to get this from url which will be provided by linked – Umesh Awasthi Apr 28 '13 at 06:49
  • @UmeshAwasthi Tks for reply. From your tip, I figured it out, I need to copy and past that URL scribe generated to the browser to get the verifier. Still have question: if I used the example's apiKey and apiSecret, I can see good response, but with my application's ones, it returned an error `Access to connections denied`. Is it because my newly-registered apps use OAuth2.0 and scribe usesd 1.0? Tks – EyeQ Tech May 01 '13 at 07:06
  • @TungMaiLe:Scribe also support OAuth 2.0. – Umesh Awasthi May 01 '13 at 08:15
  • @UmeshAwasthi tks, is there anything specific to config scribe to use OAuth2.0 or it just works out of the box? – EyeQ Tech May 01 '13 at 09:03
  • @TungMaiLe it will work out of the box. no need for any configuration – Umesh Awasthi May 01 '13 at 09:28