为什么PlusClient.loadPeople失败,HTTP 403错误? [英] Why does PlusClient.loadPeople fail with HTTP 403 error?

查看:412
本文介绍了为什么PlusClient.loadPeople失败,HTTP 403错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我老谷歌加(又名谷歌播放服务)的API集成到我的应用程序,现在我试图更新的东西来使用V2的API,其中包括,除其他事项外,进入人的名单人的圈子。

从表面上看,我不得不做出的唯一改变是更新我使用验证的OAuth简介:

  _plusClient =新PlusClient.Builder(_activity,这一点,这一点)。
        setScopes(Scopes.PLUS_LOGIN).build();
 

然后,让用户的好友请求(做必要的箍跳跃,以确保事情接通后):

  _plusClient.loadPeople(新PlusClient.OnPeopleLoadedListener(){
            公共无效onPeopleLoaded(ConnectionResult状态,PersonBuffer人,
                                        字符串nextPageToken){
                // ...
            }
        },com.google.android.gms.plus.model.people.Person.Collection.VISIBLE);
 

不过,这将导致 ConnectionResult.NETWORK_ERROR 被报告。我在Android可以看到记录以下内容:

  E /排球(13590):[4053] BasicNetwork.performRequest:对于意外的响应code 403 https://www.googleapis.com/plus/v1/people/我/人/可见光maxResults = 100安培;排序依据=按字母顺序排列
 

我的老code。使用PlusClient,获得自动的OAuth令牌后手动进行的REST请求(通过 GoogleAuthUtil.getToken )。因此,要获得一个用户的基本资料信息,我结束了发行,像这样的HTTP请求:

  https://www.googleapis.com/oauth2/v1/userinfo?auth_token=XXX
 

这工作peachily为用户信息,并继续工作用户信息与V2 code。但是,如果我尝试通过REST API来手动获取用户可见的人,像下面的要求:

  https://www.googleapis.com/plus/v1/people/me/people/visible?auth_token=XXX
 

我得到一个403响应,其内容JSON的blob:

  {
  错误: {
   错误:
    {
     域:usageLimits
     原因:accessNotConfigured
     消息:访问未配置
    }
   ]
   code:403,
   消息:访问未配置
  }
 }
 

从我可以通过文档搜集,这是没有必要获取和配置谷歌API密钥,以通过谷歌播放服务code谷歌加集成到一个Android应用程序。事实上,没有什么地方在API中提供这样的键,它证实了这种怀疑。

我正好有一个谷歌API密钥连接到我的GCM Android应用程序。在起飞的机会,该API密钥被莫名其妙地被混合在所有这一切,我已确保Goo​​gle+的启用该API密钥,但是这并没有使403响应奇迹般地消失。

我已经测试通过API浏览器嵌入到 https://www.googleapis.com/plus/v1/people/me/people/visible 要求< A HREF =htt​​ps://developers.google.com/+/api/latest/people/list相对=nofollow> REST API文档的Google+ 和它的作品出现。我可以看到在JSON结果的人在我的圈子。

我注意到,这些要求似乎有掴到URL的API密钥:

<$p$p><$c$c>https://www.googleapis.com/plus/v1/people/me/people/visible?key=AIzaSyCFj15TpkchL4OUhLD1Q2zgxQnMb7v3XaM

所以,我想创建一个API密钥为我的Andr​​oid应用程序(使用我使用的GCM相同谷歌API项目)和套结了到在code中的URL是手动尝试加载好友列表。此请求失败,401错误,说的授权信息是坏的。我假定身份验证令牌我回来从谷歌加SDK code以某种方式通过不同的API项目获得(如可能使用Android的谷歌加应用程序中的一个),当我通过我自己的键,东西让所有靠不住的。

我还没有到目前为止,一个试图消除所有使用谷歌播放服务Google+的SDK和刚刚获得OAuth访问令牌自己。我非常希望这将只是工作,我也不会浪费这么多时间来调查它。因此,也许有人在宇宙中的任何已获得这样的Google+东西的工作,也可以在一个有用的方向指向我。

解决方案

你注册数字签名的.apk文件的,在谷歌API控制台公证书?如果没有,你可以找到关于如何做到这一点<一个指令href="https://developers.google.com/+/mobile/android/getting-started#step_1_enable_the_google_api">here.

I have the old Google Plus (aka Google Play Service) API integrated into my app, and now I'm trying to update things to use the V2 API which includes, among other things, access to the list of people in a person's circles.

Ostensibly, the only changes I should have had to make are to update the OAuth profile I'm using to authenticate:

    _plusClient = new PlusClient.Builder(_activity, this, this).
        setScopes(Scopes.PLUS_LOGIN).build();

and then (after doing the necessary hoop jumping to ensure that things are connected), making a request for the user's friends:

        _plusClient.loadPeople(new PlusClient.OnPeopleLoadedListener() {
            public void onPeopleLoaded (ConnectionResult status, PersonBuffer people,
                                        String nextPageToken) {
                // ...
            }
        }, com.google.android.gms.plus.model.people.Person.Collection.VISIBLE);

However, this results in ConnectionResult.NETWORK_ERROR being reported. I can see in the Android logs the following:

 E/Volley  (13590): [4053] BasicNetwork.performRequest: Unexpected response code 403 for https://www.googleapis.com/plus/v1/people/me/people/visible?maxResults=100&orderBy=alphabetical

My old code made the REST requests manually after using the PlusClient to obtain an OAuth auto token (via GoogleAuthUtil.getToken). So to obtain a user's basic profile info, I ended up issuing an HTTP request like so:

https://www.googleapis.com/oauth2/v1/userinfo?auth_token=XXX

This worked peachily for userinfo and continues to work for userinfo with the V2 code. However, if I try to manually fetch a user's visible people via the REST API, with a request like the following:

https://www.googleapis.com/plus/v1/people/me/people/visible?auth_token=XXX

I get a 403 response with the following JSON blob:

 {                                                                                                                                  
  "error": {                                                                                                                        
   "errors": [                                                                                                                      
    {                                                                                                                               
     "domain": "usageLimits",                                                                                                       
     "reason": "accessNotConfigured",                                                                                               
     "message": "Access Not Configured"                                                                                             
    }                                                                                                                               
   ],                                                                                                                               
   "code": 403,                                                                                                                     
   "message": "Access Not Configured"                                                                                               
  }                                                                                                                                 
 }                                                                                                                                  

From what I can glean via the documentation, it is not necessary to obtain and configure a Google API key to integrate Google Plus into an Android app via the Google Play Services code. Indeed, there's nowhere in the API to supply such a key, which corroborates this suspicion.

I happen to have a Google API key connected to my Android app for GCM. On the off chance that that API key is somehow being mixed up in all of this, I have ensured that Google+ is enabled for that API key, but that did not make the 403 response magically go away.

I have tested a https://www.googleapis.com/plus/v1/people/me/people/visible request via the API explorer embedded in the REST API docs for Google+ and it works there. I can see the people in my circles in the JSON results.

I noticed that those requests appear to have an API key slapped onto the URL:

https://www.googleapis.com/plus/v1/people/me/people/visible?key=AIzaSyCFj15TpkchL4OUhLD1Q2zgxQnMb7v3XaM

So I tried creating an API key for my Android app (using the same Google API project that I'm using for GCM), and tacking that onto the URL in the code that manually attempts to load the friends list. This request fails with a 401 error saying that the authorization information is bad. I assume that the auth token I get back from the Google Plus SDK code is somehow obtained through a different "API project" (like maybe the one used by the Android Google Plus app) and when I pass my own key, things get all wonky.

I haven't gone so far a to try to eliminate all use of the Google Play Services Google+ SDK and just obtain an OAuth access token myself. I was rather hoping this would just work and I wouldn't have to waste so much time investigating it. So perhaps someone out in the universe has either gotten this Google+ stuff working or can point me in a useful direction.

解决方案

Did you register your digitally signed .apk file's public certificate in the Google APIs Console? If not, you can find instructions on how to do it here.

这篇关于为什么PlusClient.loadPeople失败,HTTP 403错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆