【问题标题】:How to fetch Google+ friends in Android如何在 Android 中获取 Google+ 好友
【发布时间】:2018-08-21 16:55:19
【问题描述】:

通过this example,我可以将 Google+ 与 android 集成并获取我的信息,例如用户 ID、网址、个人资料名称和个人资料图片。
我还想获取我所有朋友的列表并显示它。
我该怎么做?哪个类有用?

【问题讨论】:

    标签: android google-plus


    【解决方案1】:

    这可以使用 google plus api 来完成。虽然您无法在一次请求中获得每个朋友的完整个人资料信息,但它至少会为您提供以下信息

    • 身份证
    • 显示名称
    • 图片
    • 对象类型
    • 网址

    要进一步获取个人资料信息,您必须分别获取每个朋友的个人资料信息。

    下面是获取好友列表的代码

           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”用于遍历每个“Person”对象。

    现在要获取更多个人资料信息,您可以使用以下 sn-p 代码

         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.
    

    为了更清楚,请查看此链接 https://developers.google.com/+/mobile/android/people

    【讨论】:

    • 你成就了我的一天。谢谢兄弟。
    【解决方案2】:

    目前没有公开的 API 方法用于列出 G+ 用户的朋友。

    您可以在此处详细了解公开了哪些方法:https://developers.google.com/+/api/

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多