SHARE
TWEET

Untitled

a guest Aug 19th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. My code is not getting past: "What is the Authorisation code"... could u may tell me why?
  2.  
  3. ```public static Person setUp() throws IOException {
  4.         HttpTransport httpTransport = new NetHttpTransport();
  5.         JacksonFactory jsonFactory = new JacksonFactory();
  6.  
  7.         // Go to the Google API Console, open your application's
  8.         // credentials page, and copy the client ID and client secret.
  9.         // Then paste them into the following code.
  10.         String clientId = "MYID";
  11.         String clientSecret = "MYSECRET";
  12.  
  13.         // Or your redirect URL for web based applications.
  14.         String redirectUrl = "http://localhost:8080";
  15.         String scope = "https://www.googleapis.com/auth/userinfo.profile";
  16.  
  17.         // Step 1: Authorize -->
  18.         String authorizationUrl =
  19.                 new GoogleBrowserClientRequestUrl(clientId, redirectUrl, Arrays.asList(scope)).build();
  20.  
  21.         // Point or redirect your user to the authorizationUrl.
  22.         System.out.println("Go to the following link in your browser:");
  23.         System.out.println(authorizationUrl);
  24.  
  25.         // Read the authorization code from the standard input stream.
  26.         BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  27.         System.out.println("What is the authorization code?");
  28.         String s;
  29.         while( (s = in.readLine()) != null){
  30.             System.out.println("### " + s);
  31.         }
  32.         String code = in.readLine();
  33.         System.out.println("alalalalalla");
  34.         // End of Step 1 <--
  35.  
  36.         // Step 2: Exchange -->
  37.         GoogleTokenResponse tokenResponse =
  38.                 new GoogleAuthorizationCodeTokenRequest(
  39.                         httpTransport, jsonFactory, clientId, clientSecret, code, redirectUrl)
  40.                         .execute();
  41.  
  42.         System.out.println("Token Tostring: "+tokenResponse.toString());
  43.         // End of Step 2 <--
  44.  
  45.         GoogleCredential credential = new GoogleCredential.Builder()
  46.                 .setTransport(httpTransport)
  47.                 .setJsonFactory(jsonFactory)
  48.                 .setClientSecrets(clientId, clientSecret)
  49.                 .build()
  50.                 .setFromTokenResponse(tokenResponse);
  51.  
  52.         PeopleService peopleService =
  53.                 new PeopleService.Builder(httpTransport, jsonFactory, credential).build();
  54.  
  55.         Person profile = peopleService.people().get("people/me")
  56.                 .setPersonFields("names,emailAddresses")
  57.                 .execute();
  58.  
  59.  
  60.  
  61.         return profile;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top