我正在开发一个 Android 应用程序,我需要检索用户个人资料图片。我已经使用 OAuth 来获取 token ,如下所述: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}
但我无法理解关键是什么:在我的谷歌控制台上,我有:
- 网络应用程序的客户端 ID
- Android 应用程序的客户端 ID
- 服务器应用程序的 key
- Android 应用程序的 key
哪一个是正确的 key ?我有点困惑。我在检索 token 并在后端验证它时使用网络客户端 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,我会成功获取所有信息。
我做错了什么?
最佳答案
准备工作
The Getting Started with G+页面解释了如何获取 key 。
按照“第 1 步:启用 Google+ API”操作即可解决问题。
这是 Google 开发者控制台代码 fragment :
当然,您必须在控制台中启用 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 中所述。 :
If using the userId value "me", this method requires authentication using a token that has been granted the OAuth scope https://www.googleapis.com/auth/plus.login or https://www.googleapis.com/auth/plus.me. Read more about OAuth.
关于android - Android 应用程序中的 Google Plus key : What Key?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22508856/