我正在构建一个需要从登录的谷歌帐户中检索个人信息(特别是全名、个人资料图片和封面图片)的应用程序,并且我正在尝试在不实现 Google+ 登录的情况下执行此操作,我认为这有点矫枉过正在我的具体情况下。
这是我用来验证的 GoogleAccountCredential 对象
credential = GoogleAccountCredential.usingOAuth2(
getApplicationContext(), Arrays.asList(SCOPES))
.setBackOff(new ExponentialBackOff())
.setSelectedAccountName(settings.getString(PREF_ACCOUNT_NAME, null));
而 SCOPE 是
private static final String[] SCOPES = {CalendarScopes.CALENDAR_READONLY, CalendarScopes.CALENDAR, "profile", "email", "https://www.googleapis.com/auth/plus.login" };
现在,当我启动应用程序时,我得到了正确询问使用请求信息的权限:
https://www.dropbox.com/s/e11y0gnnemfgu02/Screenshot_2015-08-11-19-41-08~01.png?dl=0
当我想检索所需的数据时,我执行了一个 AsyncTask 我发出以下 GET 请求
CloseableHttpResponse response = httpClient.execute(new HttpGetHC4("https://www.googleapis.com/plus/v1/people/me"));
BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
Log.d("ProfileTask", result.toString() );
我得到这个回应
{ "error":
{ "errors":
[ { "domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console" } ],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup." }}
现在:
- 我已经在我的 Google Developer Console 中启用了 Google+ API(我实际上尝试启用它并禁用它以查看它是否有任何区别:它没有)使用与应用程序的 SHA1 指纹相关联的 OAuth 凭据
- 我还启用了日历 API,我没有从它的请求中得到任何错误
我还尝试使用创建的公共 API 密钥发出 GET 请求,例如
GET https://www.googleapis.com/plus/v1/people/me?key={MY_API_KEY}
只是为了得到相同的结果,甚至得到一个错误,它说“ipRefererBlocked 在您的 API 密钥上配置了 per-IP 或 per-Referer 限制,并且请求与这些限制不匹配。请使用 Google Developers Console 更新您的如果应允许来自此 IP 或引用者的请求,则 API 密钥配置。"
我究竟做错了什么?我是否误解了这些 API 的功能?如果不使用 Google+ 签名,我还能如何检索这些数据?
非常感谢你的帮助。
编辑:我也尝试使用从 http 请求中的 credentials.getToken() 获得的 accessToken 进行访问:
GET https://www.googleapis.com/plus/v1/people/me?accesstoken={ACCESS_TOKEN}
无济于事,和以前一样的错误。