【发布时间】:2023-04-06 03:24:01
【问题描述】:
我正在使用此链接在 google plus 上创建帖子 - https://developers.google.com/+/domains/posts/creating
我已经使用这些步骤生成了访问令牌
-
使用以下链接生成代码
https://accounts.google.com/o/oauth2/auth?client_id={client_id}&redirect_uri={redirect_uri}&scope=https://www.googleapis.com/auth/plus.stream.write https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.me&approval_prompt=force&response_type=code
结果
{redirect_uri}/?code=4/OxhUqnNDDGPPcuf_VvE7cKuL4PXehuToUTfwyrt9U&authuser=0&prompt=consent&session_state=7da4522b3012e15uigggguhgue1bd80e6adb1bfd9..66de#
收到此代码“4/OxhUqnNDDGPPcuf_VvE7cKuL4PXehuToUTfwyrt9U”和重定向 uri。
-
使用此代码,我在此 url 请求令牌
https://www.googleapis.com/oauth2/v3/token
发布参数 -
grant_type = authorization_code
code = 4/OxhUqnNDDGPPcuf_VvE7cKuL4PXehuToUTfwyrt9U
client_secret = {client_secret}
redirect_uri = {redirect_uri}
client_id = {client_id}
收到以下结果
{
"access_token": "{access_token}",
"token_type": "Bearer",
"expires_in": 3600,
"id_token": "{token_id}"
}
现在,当在 google 上创建帖子时,加上在以下 curl 请求中使用上述访问令牌时,我得到了解析错误 -
curl -v -H "Content-Type: application/json" -H "Authorization: Bearer "{access_token}" -d "{"object": {"originalContent": "Happy Monday!#caseofthemondays"},"access":{"kind":"plus#acl","items":[{"type":"domain"}],"domainRestricted":true}}" -X POST https://www.googleapis.com/plusDomains/v1/people/{user_id}/activities
结果 -
{
"error": {
"errors": [
{
"domain": "global",
"reason": "parseError",
"message": "Parse Error"
}
],
"code": 400,
"message": "Parse Error"
}
}
以下链接中没有此错误代码的描述 - https://developers.google.com/drive/web/handle-errors
同时使用这两个权限
https://www.googleapis.com/auth/plus.me
https://www.googleapis.com/auth/plus.stream.write
正如 mahendar 所建议的,它确实解决了我今天早些时候想到的解析错误。但现在我面临以下问题
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Forbidden"
}
],
"code": 403,
"message": "Forbidden"
}
}
我猜是权限不对。我已经在开发者控制台中启用了 domainPlus api。
我不知道我在这里做错了什么。任何帮助将不胜感激。
【问题讨论】:
标签: php curl google-api google-plus posts