【问题标题】:Google Plus Key in Android app: What Key?Android 应用程序中的 Google Plus Key:什么键?
【发布时间】:2014-03-19 14:21:33
【问题描述】:

我正在开发一个 Android 应用程序,我需要检索用户个人资料图片。我已经使用 OAuth 来获取令牌,如下所述:http://android-developers.blogspot.it/2013/01/verifying-back-end-calls-from-android.html

任何,我无法正确检索用户信息。我试过这个:

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

但我无法理解 KEY 是什么:在我的谷歌控制台上我有:

  • Web 应用程序的客户端 ID
  • Android 应用程序的客户端 ID
  • 服务器应用程序密钥
  • Android 应用程序密钥

其中哪一个是正确的密钥?我有点困惑。在检索令牌并在后端验证它时,我使用 Web 客户端 ID。我使用 Android 的客户端 ID 在后端检查发行者是否在授权方之间。无论如何,当我提出请求时:

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

我总是得到一个 401,400 或 403 说:

  • “未配置访问。请使用 Google Developers Console 为您的项目激活 API。”
  • 错误的请求
  • “无效凭据”

等等。

我也试过看这个问题,但没有运气:How to call https://www.googleapis.com/plus/v1/people/me at google

但如果我尝试从 Google Cloud Console 查询 Google+ API,我会成功获取所有信息。

我做错了什么?

【问题讨论】:

  • 嘿@edoardotognoni,我已经提交了一份错误报告,因为在凭证区域中创建的 Android 或 iOS 密钥实际上都不适用于 API 调用。如果可能的话,你能不能给它加注星标,这样它可能会得到适当的关注并修复?网址:code.google.com/p/google-plus-platform/issues/…

标签: android google-plus


【解决方案1】:

准备

The Getting Started with G+ 页面说明了如何获取密钥。

按照“第 1 步:启用 Google+ API”,您将解决问题。

这是 Google 开发者控制台 sn-p:

当然,您必须在控制台中启用 Google+ API

这是一个示例“页面”查询:

https://www.googleapis.com/plus/v1/people/115657794332822874007?key=my_key 

结果:

{
 "kind": "plus#person",
 "etag": "\"7zDxHg5s5mqDKJRPJZIoOsdfecE/hQCtSSux92KyaIK9CGzq7XZppYY\"",
 "urls": [
  {
   "value": "http://www.osijek360.com",
   "type": "website",
   "label": "www.osijek360.com"
  },
  {
   "value": "https://plus.google.com/+Osijek360/about",
   "type": "other",
   "label": "OSIJEK360 (page)"
  },
  {
   "value": "https://www.facebook.com/OSIJEK360",
   "type": "other",
   "label": "OSIJEK360 (fan page)"
  },
  {
   "value": "http://www.webonjee.com",
   "type": "other",
   "label": "------------------------------------\u003e www.webonjee.com"
  },
  {
   "value": "https://www.facebook.com/webonjee.osijek",
   "type": "other",
   "label": "Webonjee Osijek (profile)"
  },
  {
   "value": "https://www.facebook.com/WEBONJEE",
   "type": "other",
   "label": "WEBONJEE™ (page)"
  },
  {
   "value": "https://www.twitter.com/WEBONJEE",
   "type": "other",
   "label": "WEBONJEE™ (profile)"
  },
  {
   "value": "http://www.linkedin.com/in/webonjee",
   "type": "other",
   "label": "WEBONJEE™ (profile)"
  }
 ],
 "objectType": "page",
 "id": "115657794332822874007",
 "displayName": "OSIJEK360",
 "tagline": "Osječki web portal sa 3D – 360º virtualnim šetnjama i panoramama",
 ...
}

/我的请求

配置正确后,您还需要提供access_token 才能使用/me 请求,如API documentation 中所述:

如果使用 userId 值“me”,此方法需要身份验证 使用已被授予 OAuth 范围的令牌 https://www.googleapis.com/auth/plus.loginhttps://www.googleapis.com/auth/plus.me。阅读有关 OAuth 的更多信息。

【讨论】:

  • 是的,但在这种情况下,我使用的是 GoogleApis,无法通过 HttpGet 获取信息?
  • 您需要服务的 API 密钥才能将数据返回给您。这就是 Google 控制谁可以访问特定数据的方式。
  • 好的,谢谢,现在很清楚了。无论如何,除了 GoogleAuthUtil 之外,我还尝试在 Android 中使用 Google+ API 来获取令牌并且它正在工作。无论如何,如果我在浏览器 (googleapis.com/plus/v1/people/me?key=xxxxxxxxxxxx) 上粘贴链接,结果仍然是 401 无效凭据。也许无法通过 Web 浏览器获取它?
  • 我添加了更多详细信息。 TL;DR:您需要提供access_token
  • @edoardotognoni 您是否尝试使用access_token 提出请求?
猜你喜欢
  • 2013-08-28
  • 2016-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多