Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- My code is not getting past: "What is the Authorisation code"... could u may tell me why?
- ```public static Person setUp() throws IOException {
- HttpTransport httpTransport = new NetHttpTransport();
- JacksonFactory jsonFactory = new JacksonFactory();
- // Go to the Google API Console, open your application's
- // credentials page, and copy the client ID and client secret.
- // Then paste them into the following code.
- String clientId = "MYID";
- String clientSecret = "MYSECRET";
- // Or your redirect URL for web based applications.
- String redirectUrl = "http://localhost:8080";
- String scope = "https://www.googleapis.com/auth/userinfo.profile";
- // Step 1: Authorize -->
- String authorizationUrl =
- new GoogleBrowserClientRequestUrl(clientId, redirectUrl, Arrays.asList(scope)).build();
- // Point or redirect your user to the authorizationUrl.
- System.out.println("Go to the following link in your browser:");
- System.out.println(authorizationUrl);
- // Read the authorization code from the standard input stream.
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- System.out.println("What is the authorization code?");
- String s;
- while( (s = in.readLine()) != null){
- System.out.println("### " + s);
- }
- String code = in.readLine();
- System.out.println("alalalalalla");
- // End of Step 1 <--
- // Step 2: Exchange -->
- GoogleTokenResponse tokenResponse =
- new GoogleAuthorizationCodeTokenRequest(
- httpTransport, jsonFactory, clientId, clientSecret, code, redirectUrl)
- .execute();
- System.out.println("Token Tostring: "+tokenResponse.toString());
- // End of Step 2 <--
- GoogleCredential credential = new GoogleCredential.Builder()
- .setTransport(httpTransport)
- .setJsonFactory(jsonFactory)
- .setClientSecrets(clientId, clientSecret)
- .build()
- .setFromTokenResponse(tokenResponse);
- PeopleService peopleService =
- new PeopleService.Builder(httpTransport, jsonFactory, credential).build();
- Person profile = peopleService.people().get("people/me")
- .setPersonFields("names,emailAddresses")
- .execute();
- return profile;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement