使用 Google Plus API 获取用户的圈子列表

Get list of circles of a user using Google Plus API

我正在使用 google auth,范围如下

scope : ['https://www.googleapis.com/auth/tasks', 'https://www.googleapis.com/auth/tasks.readonly', 'https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/plus.circles.read']

我试图获取有关用户的信息,我使用了以下 API

var xhr = Ti.Network.createHTTPClient({
            onload : function() {
                var data = this.responseText;
                var json = JSON.parse(data);
                Ti.API.log('json: ' + JSON.stringify(json));
            }
        });
        xhr.open("GET", "https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=" + googleAuth.getAccessToken());
        xhr.send();

但是只提供了用户的基本信息,请问如何获取用户的朋友圈信息

我用

替换了xhr.open("GET", "https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=" + googleAuth.getAccessToken());
xhr.open("GET", "https://www.googleapis.com/plusDomains/v1/people/me/circles?access_token=" + googleAuth.getAccessToken());

控制台中的响应文本类似于

json: {"error":{"errors":[{"domain":"global","reason":"forbidden","message":"Forbidden"}],"code":403,"message":"Forbidden"}}

我已启用

API 最接近的是 People.list

https://www.googleapis.com/plus/v1/people/me/people/connected?key={YOUR_API_KEY}

尝试测试合集,看看哪一个更适合您的需求。您可以在页面底部测试结果。无法取回圈子名称。

Acceptable values are:

"connected": The list of visible people in the authenticated user's circles who also use the requesting app. This list is limited to users who made their app activities visible to the authenticated user.

"visible": The list of people who this user has added to one or more circles, limited to the circles visible to the requesting application.

截至 2018 年 8 月 Google+ API 端点 https://www.googleapis.com/plus/v1/people/userId/people/collection is deprecated.

There is a new endpoint 用于获取所有联系人:https://people.googleapis.com/v1/people/me/connections。 响应中有一个 metadata 键,对于 Google+ 联系人,它看起来有点像这样:

  "metadata": {
    "sources": [
      {
        "updateTime": "2013-01-13T19:16:50.668Z", 
        "etag": "...", 
        "type": "CONTACT", 
        "id": "..."
      }, 
      {
        "etag": "...", 
        "type": "PROFILE", 
        "id": "...", 
        "profileMetadata": {
          "userTypes": [
            "GOOGLE_USER", 
            "GPLUS_USER"
          ], 
          "objectType": "PERSON"
        }
      }
    ], 
    "objectType": "PERSON"
  }

注意 "GPLUS_USER" 部分。