How to fetch Google+ friends in Android

后端 未结 2 1498
臣服心动
臣服心动 2021-01-06 20:04

Through this example I am able to integrate Google+ with android and to fetch my information like user id, url, profile name and profile picture.
I want also to fetch t

相关标签:
2条回答
  • 2021-01-06 20:30

    This can be done using google plus api. Though you can not get full profile information of every friend in one request, it will give you at least following information

    • id
    • displayName
    • image
    • objectType
    • url

    To get profile information further you have to fetch each friend's profile information separately.

    Given below is the code to fetch friends list

           mPlusClient.loadPeople(new OnPeopleLoadedListener()
            {
    
                @Override
                public void onPeopleLoaded(ConnectionResult status, PersonBuffer personBuffer, String nextPageToken)
                {
    
                    if ( ConnectionResult.SUCCESS == status.getErrorCode() )
                    {
                        Log.v(TAG, "Fetched the list of friends");
                        for ( Person p : personBuffer )
                        {
                            Log.v(TAG, p.getDisplayName());
                        }
                    }
                }
            }, Person.Collection.VISIBLE); // VISIBLE=0
        }
    

    "for-loop" in the callback is there to iterate over each "Person" object.

    Now to get further profile information you can use following snippet of code

         mPlusClient.loadPerson(new OnPersonLoadedListener()
            {
    
                @Override
                public void onPersonLoaded(ConnectionResult status, Person person)
                {
                    if ( ConnectionResult.SUCCESS == status.getErrorCode()) 
                    {
                        Log.v(TAG, person.toString());
                    }
    
                }
            }, "me"); // Instead of "me" use id of the user whose profile information you are willing to get.
    

    For further clarity please take a look at this link https://developers.google.com/+/mobile/android/people

    0 讨论(0)
  • 2021-01-06 20:30

    There is not currently an API method exposed to list friends of a G+ user.

    You can learn more about what methods are exposed here: https://developers.google.com/+/api/

    0 讨论(0)
提交回复
热议问题