简体   繁体   English

禁止使用Google+域API 403

[英]Google+ Domains API 403 Forbidden

I'm trying to create Circles with the Google+ API, but I'm kinda stuck, this is my code, it was more or less copied from the official API documentation (yes I know it doesn't create Circle, but the issue is the same) 我正在尝试使用Google+ API创建Circles,但是有点卡住了,这是我的代码,它或多或少是从官方API文档中复制的(是的,我知道它不会创建Circle,但是问题是相同)

import httplib2

from apiclient.discovery import build
from oauth2client.client import OAuth2WebServerFlow
import json

with open('client_secrets.json', 'r') as f:
    json_data = json.load(f)

data = json_data['web']
CLIENT_ID = data['client_id']
CLIENT_SECRET = data['client_secret']

# List the scopes your app requires:
SCOPES = ['https://www.googleapis.com/auth/plus.me',
          'https://www.googleapis.com/auth/plus.circles.write']

# The following redirect URI causes Google to return a code to the user's
# browser that they then manually provide to your app to complete the
# OAuth flow.
REDIRECT_URI = 'http://localhost/oauth2callback'

# For a breakdown of OAuth for Python, see
# https://developers.google.com/api-client-library/python/guide/aaa_oauth
# CLIENT_ID and CLIENT_SECRET come from your APIs Console project
flow = OAuth2WebServerFlow(client_id=CLIENT_ID,
                           client_secret=CLIENT_SECRET,
                           scope=SCOPES,
                           redirect_uri=REDIRECT_URI)

auth_uri = flow.step1_get_authorize_url()

# This command-line server-side flow example requires the user to open the
# authentication URL in their browser to complete the process. In most
# cases, your app will use a browser-based server-side flow and your
# user will not need to copy and paste the authorization code. In this
# type of app, you would be able to skip the next 3 lines.
# You can also look at the client-side and one-time-code flows for other
# options at https://developers.google.com/+/web/signin/
print 'Please paste this URL in your browser to authenticate this program.'
print auth_uri
code = raw_input('Enter the code it gives you here: ')

# Set authorized credentials
credentials = flow.step2_exchange(code)

# Create a new authorized API client.
http = httplib2.Http()
http = credentials.authorize(http)
service = build('plusDomains', 'v1', http=http)

from apiclient import errors
try:
    people_service = service.people()
    people_document = people_service.get(userId='me').execute()
except errors.HttpError, e:
    print e.content

My output: 我的输出:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "forbidden",
    "message": "Forbidden"
   }
  ],
  "code": 403,
  "message": "Forbidden"
 }
}

I searched for answer, but didn't really find any. 我搜索了答案,但没有真正找到答案。 On the API console I have Google+ API and Google+ Domains API services added also my secret and client id are okay (otherwise the whole script would fail sooner). 在API控制台上,我添加了Google+ API和Google+ Domains API服务,我的密码和客户端ID都可以(否则整个脚本很快就会失败)。 Also the auth is successful, my app's name is shown under https://accounts.google.com/IssuedAuthSubTokens . 验证也成功,我的应用程序名称显示在https://accounts.google.com/IssuedAuthSubTokens下。 What did I miss? 我错过了什么?

The problem lies with your REDIRECT_URI variable. 问题出在您的REDIRECT_URI变量上。 When you are using OAuth 2.0 in a purely server-side flow, the redirect URI MUST be 'urn:ietf:wg:oauth:2.0:oob' . 在纯服务器端流程中使用OAuth 2.0时,重定向URI务必为'urn:ietf:wg:oauth:2.0:oob'

Try changing the variable like so (and be sure to update your client ID in the API Console): REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob' 尝试像这样更改变量(并确保在API控制台中更新客户端ID): REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob'

Edit: Also, make sure that you are making your API call for a user within a domain. 编辑:此外,请确保您正在为域内的用户进行API调用。 The Google+ Domains API only permits API calls that are restricted to users and content within that domain. Google+域API仅允许限于该域内的用户和内容的API调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 禁止使用Google Analytics(分析)API获取错误403 - Getting Error with Google Analytics API 403 Forbidden 403禁止在Google日历API上使用endTimeUnspecified吗? - 403 Forbidden with endTimeUnspecified on Google calendar API? 403在Python中使用Google+ API时未经授权 - 403 Unauthorized when using Google+ API in Python Google QPX Express API返回HTTP错误403:禁止访问 - Python - Google QPX Express API returning HTTP error 403 : Forbidden - Python google.api_core.exceptions.Forbidden:403 权限缺失或不足 - google.api_core.exceptions.Forbidden: 403 Missing or insufficient permissions 谷歌测试工具 API - MobileFriendlyTest Python 403 Forbidden - Google Testing Tools API - MobileFriendlyTest Python 403 Forbidden 使用令牌调用google + API - Call google+ API with token Python AppEngine的Google Url Shortener API:HTTP错误:HTTP错误403:禁止 - Google Url Shortener API from Python AppEngine: HTTPError: HTTP Error 403: Forbidden Google ML Engine和Python数据存储API,'禁止访问:403请求的身份验证范围不足。' - Google ML Engine and Python Datastore API, 'Forbidden: 403 Request had insufficient authentication scopes.' HTTPError:HTTP 错误 403:Google Colab 上禁止 - HTTPError: HTTP Error 403: Forbidden on Google Colab
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM