How to get gender and birthday of a user's google sign using People API, Oauth 2 API in Android?

All answers on SO seem outdated and com.google.android.gms.plus. People are also deprecated, which Google used in the People API documentation. Attaching the code below

public void setUp() throws IOException {
    HttpTransport httpTransport = new NetHttpTransport();
    JacksonFactory jsonFactory = new JacksonFactory();


    String clientId = "YOUR_CLIENT_ID";
    String clientSecret = "YOUR_CLIENT_SECRET";

    String redirectUrl = "urn:ietf:wg:oauth:2.0:oob";
    String scope = "https://www.googleapis.com/auth/contacts.readonly";


    String authorizationUrl = new GoogleBrowserClientRequestUrl(clientId,
                                                                redirectUrl,
                                                                Arrays.asList(scope))
        .build();

    System.out.println("Go to the following link in your browser:");
    System.out.println(authorizationUrl);


    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("What is the authorization code?");
    String code = in.readLine();

    GoogleTokenResponse tokenResponse = new GoogleAuthorizationCodeTokenRequest(
        httpTransport, jsonFactory, clientId, clientSecret, code, redirectUrl).execute();


    GoogleCredential credential = new GoogleCredential.Builder()
        .setTransport(httpTransport)
        .setJsonFactory(jsonFactory)
        .setClientSecrets(clientId, clientSecret)
        .build()
        .setFromTokenResponse(tokenResponse);

    People peopleService = new People.Builder(httpTransport, jsonFactory, credential)
        .build();
    ...
  }

      

+3


source to share


1 answer


You should get an authenticated user profile by doing "people / me" as in the example at https://developers.google.com/people/v1/requests#get-the-users-profile

You will need the following permissions: - profile - (Lets use "people / me" to get authenticated user) - https://www.googleapis.com/auth/user.birthday.read - (to get the user's birthday)



Right now for the floor, you will only get it if it goes public. There is no way to get a private floor.

0


source







All Articles