Skip to content Skip to sidebar Skip to footer

How To Get Profile Id Of Connections Using Google People Api In Android?

I'm working on an App and this app has a feature, which need profile ID of Google Account. I can get data using Google People API by using code: GoogleSignInOptions signInOptions

Solution 1:

For getting Profile_id you should use GoogleSignInAccount class like this it's included in GoogleSignInOptions.

publicvoidsignIn() {
    IntentsignInIntent= Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
    this.startActivityForResult(signInIntent, RC_SIGN_IN);
}

@OverridepublicvoidonActivityResult(int requestCode, int resultCode, Intent data)  {
    //this.onActivityResult(requestCode, resultCode, data);super.onActivityResult(requestCode, resultCode, data);
    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);if (requestCode == RC_SIGN_IN) {
        GoogleSignInResultresult= Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        handleSignInResult(result);
    }
    else {
        Log.i("TAG", "request" + requestCode + " ResultCode" + resultCode + " FilterItem_Data " + data);
        mCallbackManager.onActivityResult(requestCode, resultCode, data);

    }
}

After geting result:

privatevoidhandleSignInResult(GoogleSignInResult result)   {
    //Log.d(TAG, "handleSignInResult:" + result.isSuccess());if (result.isSuccess()) {
        // Signed in successfully, show authenticated UI.GoogleSignInAccountacct= result.getSignInAccount();
        StringpersonName= acct.getDisplayName();
        StringpersonEmail= acct.getEmail();
        StringpersonId= acct.getId();

A person id is your profile_id hope this will help you.

Solution 2:

If you request "person.metadata" in your request mask. Then it will return person.metadata.sources. You can go through each source and if the source has type profile, then the source ID will be the profile ID. See documentation for more info.

Note: there may be more than one profile per contact.

Solution 3:

I found my solution. It 's just a "setPageSize" setting property in ListConnectionsResponse assignment. Fully, assignment likes that:

ListConnectionsResponseresponse= peopleService.people().connections()
                        .list("people/me")
                        .setPageSize(1200)
                   .setRequestMaskIncludeField("person.names,person.emailAddresses,person.phoneNumbers")
                        .execute();

Post a Comment for "How To Get Profile Id Of Connections Using Google People Api In Android?"