簡體   English   中英

403禁止的錯誤google plus python

[英]403 Forbidden error google plus python

有我的代碼:

import pprint
import httplib2

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

SCOPES = ['https://www.googleapis.com/auth/plus.me',
          'https://www.googleapis.com/auth/plus.stream.write']

REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob'

CLIENT_ID = "my client id"
CLIENT_SECRET = "my client secret"
flow = OAuth2WebServerFlow(client_id=CLIENT_ID,
                           client_secret=CLIENT_SECRET,
                           scope=SCOPES,
                           redirect_uri=REDIRECT_URI)

auth_uri = flow.step1_get_authorize_url()

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: ')

credentials = flow.step2_exchange(code)

http = httplib2.Http()
http = credentials.authorize(http)
service = build('plusDomains', 'v1', http=http)

user_id = 'me'

print('Insert activity')
result = service.activities().insert(
    userId = user_id,
    body = {
        'object' : {
            'originalContent' : 'Happy Monday! #caseofthemondays'
        },
        'access' : {
            'items' : [{
                'type' : 'domain'
            }],
            'domainRestricted': True
        }
    }).execute()
print('result = %s' % pprint.pformat(result))

還有我的錯誤:

Traceback (most recent call last):
      File "/home/karl/workspace/googleplus/google_plus/google_plus_pic.py", line 44, in <module>
        'domainRestricted': False
      File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py", line 128, in positional_wrapper
        return wrapped(*args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/apiclient/http.py", line 680, in execute
        raise HttpError(resp, content, uri=self.uri)
    apiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/plusDomains/v1/people/me/activities?alt=json returned "Forbidden">

我已經閱讀了很多信息,但是我不知道如何解決該問題。 錯誤在哪里?

要使用Google+ Domains API,您需要確保您所代表的用戶的域已為您的應用設置了正確的權限。 這些說明在快速入門指南的步驟1的“將域范圍的權限委派給您的服務帳戶”下。

具體來說,您需要將應用的客戶端ID與應用將在域的控制面板中使用的范圍相關聯。 域管理員是唯一可以執行此操作的人-因此,如果您正在使用另一個域,請確保與該人聯系。 另外,控制面板中列出的范圍必須與您在應用程序中要求的范圍完全匹配。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM