Not getting friends list in google plus android

485 views Asked by At

I want to get user circle's list of visible friends name and email address with Google Plus.

I have done following code and tried with 4 to 5 phone but in all I am getting zero list

class MainActivity extends Activity implements ConnectionCallbacks,
        OnConnectionFailedListener, ResultCallback<People.LoadPeopleResult> {

    private static final int RC_SIGN_IN = 22;

    private static final String TAG = null;

    private GoogleApiClient mGoogleApiClient;

    private boolean mIntentInProgress;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this).addApi(Plus.API)
                .addScope(Plus.SCOPE_PLUS_LOGIN)
                .addScope(Plus.SCOPE_PLUS_PROFILE)
                .build();
    }

    protected void onStart() {
        super.onStart();
        mGoogleApiClient.connect();
    }

    protected void onStop() {
        super.onStop();

        if (mGoogleApiClient.isConnected()) {
            mGoogleApiClient.disconnect();
        }
    }

    @Override
    public void onConnectionFailed(ConnectionResult result) {

    }

    @Override
    public void onConnected(Bundle arg0) {
        System.out.println("onConnected");

        Plus.PeopleApi.loadVisible(mGoogleApiClient, null).setResultCallback(
                this);

    }
    @Override
    public void onResult(LoadPeopleResult peopleData) {
        System.out.println("onResult");
        if (peopleData.getStatus().getStatusCode() == CommonStatusCodes.SUCCESS) {
            PersonBuffer personBuffer = peopleData.getPersonBuffer();
            try {
                System.out.println("PersonBuffer : - "
                        + personBuffer.getCount()); <=======HERE I AM GETTING ALWAYS 0
                int count = personBuffer.getCount();
                for (int i = 0; i < count; i++) {
                    Log.d(TAG, "Display name: "
                            + personBuffer.get(i).getDisplayName());
                }
            } finally {
                personBuffer.close();
            }
        } else {
            Log.e(TAG,
                    "Error requesting visible circles: "
                            + peopleData.getStatus());
        }
    }

    @Override
    public void onConnectionSuspended(int arg0) {
        // TODO Auto-generated method stub

    }
1

There are 1 answers

1
Bass Pj On

Please check the following cases below

  1. On the Consent Screen, you don't select circle which allow to see in your app

    1.1 When the consent screen is showing after login to google+ in your app, Click on the first sentence 'Know your basic profile info and list of people in your circle'

    1.2 Be sure that you select 'All circles', or any non-empty circle

  2. Your google+ account was set disallow your app to see the people in circle

    2.1 Open Google+ app

    2.2 Select 'Settings'

    2.3 In the 'Account Settings' section, Select your account

    2.4 Select 'Apps with Google+ Sign-in'

    2.5 Select 'All apps & devices'

    2.6 Select your app

    2.7 In the 'This app can see these people', Be sure that it select 'All circles' or any non-empty circle.

    2.8 For more detail, see the 'Change your Google+ Sign-In settings', In the 'Manage who in your circles the app can view' section in link below

    https://support.google.com/plus/answer/2980770?hl=en