我正在为我的雇主开发一个使用Google API Python客户端的Python脚本。但是,我通过SignedJwtAssertionCredentials遇到OAuth身份验证问题。相关代码如下:
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials
SERVICE_ACCOUNT_EMAIL = 'abunchofmumbojumbo@developer.gserviceaccount.com'
SERVICE_ACCOUNT_PKCS12_FILE_PATH = 'key.p12'
USER_EMAIL = 'emailaccountusedtoaccessdeveloperconsole@gmail.com'
f = file(SERVICE_ACCOUNT_PKCS12_FILE_PATH, 'rb')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(
SERVICE_ACCOUNT_EMAIL,
key,
scope='https://www.googleapis.com/auth/youtube',
sub=USER_EMAIL)
http = httplib2.Http()
http = credentials.authorize(http)
service = build('youtube', 'v3', http=http)
这是Python执行代码时返回的内容:
oauth2client.client.AccessTokenRefreshError: unauthorized_client
我试图在线搜索我如何解决这个问题,但我找不到任何东西。我最好的猜测是我没有将正确的变量传递给SignedJwtAssertionCredentials,但我不完全确定是这种情况。任何帮助将不胜感激。