403访问时出错/禁止https://www.googleapis.com/auth/plus.profiles.read 用python

403访问时出错/禁止https://www.googleapis.com/auth/plus.profiles.read 用python,python,google-api,google-plus,google-api-python-client,Python,Google Api,Google Plus,Google Api Python Client,当我尝试访问用户配置文件时,我收到一个“HttpError 403”。我按照教程,在中央面板中设置了所有权限。以下是代码: import httplib2 import pprint from apiclient.discovery import build from oauth2client.client import SignedJwtAssertionCredentials SERVICE_ACCOUNT_EMAIL = 'xxxx@developer.gserviceaccount

当我尝试访问用户配置文件时,我收到一个“HttpError 403”。我按照教程,在中央面板中设置了所有权限。以下是代码:

import httplib2
import pprint

from apiclient.discovery import build

from oauth2client.client import SignedJwtAssertionCredentials

SERVICE_ACCOUNT_EMAIL = 'xxxx@developer.gserviceaccount.com'
SERVICE_ACCOUNT_PKCS12_FILE_PATH = '/xxxx/privatekey.pem'
USER_EMAIL = 'xyz@test.com'

SCOPES = ['https://www.googleapis.com/auth/plus.profiles.read']

def authenticate():
    print "opening the key"
    f = open(SERVICE_ACCOUNT_PKCS12_FILE_PATH, 'rb')
    key = f.read()
    f.close()
    print "closing the key"

    credentials = SignedJwtAssertionCredentials(SERVICE_ACCOUNT_EMAIL, key, scope=SCOPES, sub=USER_EMAIL)
    http = httplib2.Http()
    http = credentials.authorize(http)

    print "getting the credentials"
    return build('plusDomains', 'v1', http=http)

print "calling the authentication"
service = authenticate()

print "calling people service"
people_service = service.people()

print "getting the user profile"
people_document = people_service.get(userId='abc@test.com').execute()

print 'ID: %s' % people_document.get('id')
print 'Display name: %s' % people_document.get('displayName')
print 'Image URL: %s' % people_document.get('image').get('url')
print 'Profile URL: %s' % people_document.get('url')
以下是答复:

calling the authentication
opening the key
closing the key
getting the credentials
calling people service
getting the user profile
Traceback (most recent call last):
  File "test.py", line 39, in <module>
    people_document = people_service.get(userId='abc@test.com').execute()
  File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py", line 132, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/apiclient/http.py", line 723, in execute
    raise HttpError(resp, content, uri=self.uri)
apiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/plusDomains/v1/people/abc@test.com?alt=json returned "Forbidden">
调用身份验证
打开钥匙
关钥匙
获取凭证
呼叫人员服务
获取用户配置文件
回溯(最近一次呼叫最后一次):
文件“test.py”,第39行,在
people\u document=people\u service.get(userId=)abc@test.com)。执行()
文件“/usr/local/lib/python2.7/dist packages/oauth2client/util.py”,第132行,位于位置包装器中
已包装退货(*args,**kwargs)
文件“/usr/local/lib/python2.7/dist packages/apiclient/http.py”,执行中的第723行
raise HttpError(resp,content,uri=self.uri)
apiclient.errors.HttpError:
顺便说一下,这是我在谷歌的CPANEL中使用的示波器


我们以前就有过这样的功能,但一个月前就不起作用了。欢迎提供任何帮助。

您是否尝试过使用实际的I'd而不是电子邮件地址?文档似乎不支持userId的电子邮件。它通常使用userId=电子邮件地址,您是否有更多信息可以从哪里获取ID?userId通常由使用userId=me或通过people.list调用people.get。感谢您提供的提示,我正在查看people.list,但仍然需要userId()。我需要使用电子邮件地址获取。该项目旨在获取我公司域下的所有用户,并使用picts创建员工目录。您最好使用