在客户端登录后,Google Plus API人员列表在服务器上不返回任何内容

时间:2016-03-30 12:30:05

标签: google-api google-plus-signin

我有一个登录Google的网络客户端,并将oauthtoken发送到服务器:

//Api google plus
    (function() {
        var po = document.createElement('script'); 
        po.type = 'text/javascript'; 
        po.async = true;
        po.src = 'https://apis.google.com/js/client.js?onload=onLoadCallback';
        var s = document.getElementsByTagName('script')[0]; 
        s.parentNode.insertBefore(po, s);
    })();

    function onLoadCallback(){
        gapi.client.setApiKey('AIzaSyBXXXXXX'); //set your API KEY
        gapi.client.load('plus', 'v1',function(){});//Load Google + API
    }

    $scope.loginGooglePlus = function() {
      var myParams = {
        'clientid' : 'XXXXXXX',
        'cookiepolicy' : 'single_host_origin',
        'callback': $scope.loginGooglePlusCallback,
        'scope': 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/plus.me'
      };
      gapi.auth.signIn(myParams);
    }

    $scope.loginGooglePlusCallback = function(result){
        if(result['status']['signed_in']){ 
            //alert("Login Success");
            console.log(result);
            UserAuth.loginGooglePlus(result.access_token);
        }   
    }

因此,在服务器上我尝试获取人物朋友列表:

String graphFace = "https://www.googleapis.com/plus/v1/people/me/people/visible?key=XXXXXXXXXXXXXXX&access_token=" + oauthToken;

                urlAccess = new URL(graphFace);
                URLConnection faceConnection = urlAccess.openConnection();
                faceConnection.setRequestProperty("Content-Type", "application/json;charset=utf-8;");

                BufferedReader in = new BufferedReader( new InputStreamReader(faceConnection.getInputStream()));

                String fileJson = "", strJson = "";
                while ((strJson = in.readLine()) != null)
                    fileJson = fileJson + strJson + "\n";

                createFriendTopologyFromGoogle(person, fileJson);

人员名单总是空着。但是如果我在API Explorer(https://developers.google.com/apis-explorer/#p/plus/v1/plus.people.list)中执行相同的命令,一切正常。

此命令人员列表仅适用于客户端吗?

2 个答案:

答案 0 :(得分:0)

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

将返回

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "authError",
    "message": "Invalid Credentials",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Invalid Credentials"
 }
}

因为需要身份验证,请尝试发送以下内容

https://www.googleapis.com/plus/v1/people/me/people/visible?access_token={Token from oauth2 authentcation}

答案 1 :(得分:0)

我解决了输入https://plus.google.com/u/0/apps的问题,并释放了对我的应用的所有权限。我是对2位用户这样做的。

现在,我需要使用此权限登录已经存在的用户。我不知道这部分。