我正在使用此链接在Google +上创建帖子 - 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#
通过重定向uri收到此代码“4 / OxhUqnNDDGPPcuf_VvE7cKuL4PXehuToUTfwyrt9U”。
使用此代码我在此网址上发出了令牌请求
https://www.googleapis.com/oauth2/v3/token
post params -
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}"
}
现在,在以下curl请求中使用上述访问令牌在google plus上创建帖子时,我得到了解析错误 -
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。
我不知道我在这里做错了什么。任何帮助将不胜感激。
答案 0 :(得分:1)
试试这个: -
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/me/activities"