2
我已经为我的Google日历API项目设置了服务帐户。我们的想法是,我的网站能够连接到我的谷歌日历和展示活动等。因为它是由谷歌HttpAccessTokenRefreshError at ... unauthorized_client:客户端未经授权使用此方法检索访问令牌
Service account clients are created when domain-wide delegation is
enabled on a service account.
这的确发生了,所以我有一个连接OAuth 2.0 client ID
放。到现在为止还挺好。我产生了json
文件,我用来连接,并尝试使用此代码
from cal.models import Cal as Caldb
import httplib2
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import OAuth2WebServerFlow
from oauth2client import tools
from calendar import monthrange
from calendar_gui import MyCalendar
from datetime import datetime
from datetime import date
from django.utils.safestring import mark_safe
from oauth2client.service_account import ServiceAccountCredentials
import os
from django.conf import settings
def authenticate():
scope= ['https://www.googleapis.com/auth/calendar']
credentials = ServiceAccountCredentials.from_json_keyfile_name(os.path.join(settings.PROJECT_ROOT, '../', 'myjson.json'), scopes=scope)
delegated_credentials = credentials.create_delegated('[email protected]')
http = httplib2.Http()
http = delegated_credentials.authorize(http)
service = build(serviceName='calendar', version='v3', http=http, credentials=credentials)
return service
但可惜
service = build(serviceName='calendar', version='v3', http=http, credentials=credentials)
File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py", line 137, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/googleapiclient/discovery.py", line 214, in build
cache)
File "/usr/local/lib/python2.7/dist-packages/googleapiclient/discovery.py", line 261, in _retrieve_discovery_doc
resp, content = http.request(actual_url)
File "/usr/local/lib/python2.7/dist-packages/oauth2client/transport.py", line 153, in new_request
credentials._refresh(orig_request_method)
File "/usr/local/lib/python2.7/dist-packages/oauth2client/client.py", line 765, in _refresh
self._do_refresh_request(http_request)
File "/usr/local/lib/python2.7/dist-packages/oauth2client/client.py", line 834, in _do_refresh_request
raise HttpAccessTokenRefreshError(error_msg, status=resp.status)
HttpAccessTokenRefreshError: unauthorized_client: Client is unauthorized to retrieve access tokens using this method.
我已经启用了谷歌日历API进行身份验证。事实上,我觉得我已经遵循了所有的步骤。事实上,我已经完成了一次,取得了圆满的成功,但现在我很困惑。我读到,也许我需要等24-48小时才能生效。它可以这么简单吗?
现在,我只是在本地进行测试。没有推送到服务器。
我看到了,但我只是试图连接为我自动生成的'json'文件以及客户端密钥。 –