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 the list of all my friends and to show it.
How can I do this and which class is useful?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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
回答2:
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/