use*_*661 30 python google-api oauth-2.0
我正在尝试通过Python客户端使用此代码访问谷歌应用程序以获得授权(私人信息显然已编辑):
import gflags
import httplib2
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import SignedJwtAssertionCredentials
from oauth2client.tools import run
f = open('privatekey.p12', 'rb')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(
service_account_name='name@developer.gserviceaccount.com',
private_key=key,
scope = 'https://www.googleapis.com/auth/calendar')
http = httplib2.Http()
http = credentials.authorize(http)
service = build(serviceName='calendar', version='v3', http=http)
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误:
ImportError: cannot import name SignedJwtAssertionCredentials
Run Code Online (Sandbox Code Playgroud)
我安装了Google v3 API Python客户端以及OAuth2; 我似乎没有对这些模块有任何其他问题,尽管我没有太多使用它们.有谁知道发生了什么?
Loc*_*ane 68
我今天遇到了这个问题,不得不从oauth2client 2.0版回滚到版本1.5.2:
pip install oauth2client==1.5.2
Run Code Online (Sandbox Code Playgroud)
小智 22
好像你没有安装pyopenssl.通过安装easy_install pyopenssl.
Libraries oauth2client.client
if HAS_OPENSSL:
# PyOpenSSL is not a prerequisite for oauth2client, so if it is missing then
# don't create the SignedJwtAssertionCredentials or the verify_id_token()
# method.
class SignedJwtAssertionCredentials(AssertionCredentials):
....
Run Code Online (Sandbox Code Playgroud)
该源代码库最近进行了更新,以使用新的代码:
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
41502 次 |
| 最近记录: |