how to get email id from google api response

Posted by user1726508 on Stack Overflow See other posts from Stack Overflow or by user1726508
Published on 2012-11-09T04:36:31Z Indexed on 2012/11/09 5:00 UTC
Read the original article Hit count: 161

Filed under:
|
|

i am able to get user information from Google API response using oath2 . But i do't know how to get those responses individually .

Response i am getting from Google Api: *

Access token: ya29.AHES6ZQ3QxKxnfAzpZasdfd23423NuxJs29gMa39MXV551yMmyM5IgA 
     {
     "id": "112361893525676437860",
     "name": "Ansuman Singh",
     "given_name": "Ansuman",
     "family_name": "Singh",
     "link": "https://plus.google.com/112361893525676437860",
     "gender": "male",
     "birthday": "0000-03-18",
     "locale": "en"
    }
    Original Token: ya29.AHES6ZQ3QxKxnfAzpZu0lYHYu8sdfsdafdgMa39MXV551yMmyM5IgA New Token: ya29.AHES6ZQ3QxKxnfdsfsdaYHYu8TNuxJs29gMa39MXV551yMmyM5IgA 

But i want only "id" & "name" indiviually to save in my Database table. How can i do this?

I got those above response/output By using the below code.

             public static void main(String[] args) throws IOException 
          {

            -------------------------
            -------------------------
            -------------------------        

            String accessToken = authResponse.accessToken;
            GoogleAccessProtectedResource access = new GoogleAccessProtectedResource(accessToken, TRANSPORT, JSON_FACTORY, CLIENT_ID, CLIENT_SECRET, authResponse.refreshToken); 
            HttpRequestFactory rf = TRANSPORT.createRequestFactory(access);
            System.out.println("Access token: " + authResponse.accessToken); 
            String url = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token="   + authResponse.accessToken;
                final StringBuffer r = new StringBuffer(); 
                    final URL u = new URL(url);
                    final URLConnection uc = u.openConnection();
                    final int end = 1000;
                    InputStreamReader isr = null;
                    BufferedReader br = null; 
                        isr = new InputStreamReader(uc.getInputStream());
                        br = new BufferedReader(isr);
                        final int chk = 0;
                        while ((url = br.readLine()) != null)
                        {
                            if ((chk >= 0) && ((chk < end)))
                            {
                                r.append(url).append('\n');
                            }
                         } 
              System.out.print("");
              System.out.println();
 System.out.print(" "+   r ); //this is printing at once but i want them individually
              access.refreshToken();
 System.out.println("Original Token: " + accessToken + " New Token: " + access.getAccessToken());
          }

© Stack Overflow or respective owner

Related posts about java

Related posts about google-api