Get list of circles of a user using Google Plus API

99封情书 提交于 2019-12-08 05:06:11

问题


I am using google aouth with following in scope

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']

I tried to get information about user, I've used following 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();

but it only gives information about users basic info, how can I get information about users friends in circle.

I replaced xhr.open("GET", "https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=" + googleAuth.getAccessToken()); with

xhr.open("GET", "https://www.googleapis.com/plusDomains/v1/people/me/circles?access_token=" + googleAuth.getAccessToken());

the responce text in console was like

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

I have enabled

  • Google+ API,
  • Blogger API,
  • Google+ Pages API,
  • Google+ Domains API,

回答1:


The closest thing to this that the API has is People.list

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

Try testing the collection see which one suits your needs more. You can test the results at the bottom of the page. There is no way to get the name of the circle back.

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.




回答2:


As of August 2018 the Google+ API endpoint https://www.googleapis.com/plus/v1/people/userId/people/collection is deprecated.

There is a new endpoint for getting all the contacts: https://people.googleapis.com/v1/people/me/connections. There is a metadata key in the response, and for Google+ contacts it will look somewhat like this:

  "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"
  }

Note the "GPLUS_USER" part.



来源:https://stackoverflow.com/questions/29674435/get-list-of-circles-of-a-user-using-google-plus-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!