我试图在我的Python 3.4应用程序中使用Google云端存储实现服务器到服务器的OAuth身份验证。所以,一般而言,此页Using OAuth 2.0 for Server to Server Applications使用Python 3.4的服务器到服务器应用程序的OAuth 2.0无法导入名称'SERVICE_ACCOUNT'
的描述,但同时我跑我的剧本有一个错误:
Traceback (most recent call last):
File "my_script.py", line 4, in from oauth2client.service_account import ServiceAccountCredentials
File "/usr/local/lib/python3.4/dist-packages/oauth2client/service_account.py", line 31, in from oauth2client.client import SERVICE_ACCOUNTImportError: cannot import name 'SERVICE_ACCOUNT'
所以,这里是我的代码:
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
from httplib2 import Http
scopes = ['https://www.googleapis.com/auth/cloud-platform.read-only']
credentials = ServiceAccountCredentials.from_json_keyfile_name('./keyfile.json', scopes)
http_auth = credentials.authorize(Http())
service = build('storage', 'v1', http=http_auth)
,如果您如此善良,以帮助我,这将是伟大的!这是我在Python语言中的第一个脚本之一,我是Python和Linux世界的新手,所以我可能会错过一些非常明显的东西。
如果它很重要,我的操作系统是Ubuntu 12.04。
谢谢!
你需要显示其余的错误信息 – barny
@ barny,哦,对不起,我的坏。我更新了问题中的错误文本,这就是我在运行脚本时获得的所有内容 –
您是否尝试过搜索Google支持论坛https://groups.google.com/forum/#!forum/google-api- python-client – barny