“unauthorized_client:客户未经授权使用此方法检索访问令牌”Python Gmail API使用服务帐户

时间:2018-05-10 19:27:46

标签: python google-api-client google-oauth2 google-api-python-client

我一直收到上述错误,我不知道如何解决这个问题。 我已启用域范围授权,并且还在“管理API访问”

中授权了Client-Id

我的代码如下:

"""
Sample program    
"""

import googleapiclient.discovery
import json
import googleapiclient.errors 
from google.oauth2 import service_account 

SERVICE_ACCOUNT_FILE = 'abcd.json' 

credentials = service_account.Credentials.from_service_account_file(
    SERVICE_ACCOUNT_FILE)

scoped_credentials = 
credentials.with_scopes(['https://mail.google.com/'])
delegated_credentials = credentials.with_subject('abcd')

service = googleapiclient.discovery.build('gmail','v1',credentials = delegated_credentials) 

try:
    results = service.users().labels().list(userId='abcd').execute()
except Exception as err:
    print err

有人有这个工作吗?如果是这样,请指出我收到错误的原因。

0 个答案:

没有答案
相关问题