OAuth2 for Google API on Python for Contacts

2024-09-28 19:26:11 发布

您现在位置:Python中文网/ 问答频道 /正文

好吧,我按照下面的答案: Is it possible to use "Domain-wide Delegation of Authority" with gdata-python-client?

但是,当我运行我的测试时,我得到的是:

oauth2client.client.AccessTokenRefreshError: access_denied

我的代码是:

class OAuthToken():
def __init__(self, creds):
    self.creds = creds
def modify_request(self, req):
    if self.creds.access_token_expired or not self.creds.access_token:
        self.creds.refresh(httplib2.Http())
    self.creds.apply(req.headers)

def ListContacts(username):

file    =   open('privatekey.pem','rb')
text    =   file.read()
file.close()
credentials =   SignedJwtAssertionCredentials('somelongnumber@developer.gserviceaccount.com',\
                text,\
                scope=['http://www.google.com/m8/feeds/'],\
                prn=username+'@mycompany.com')

gdclient    =   gdata.contacts.client.ContactsClient(source='mycompany.com')
gdclient.auth_token =   OAuthToken(credentials)
feed    =   gdclient.GetContacts()

我的其他OAuth2工具都能正常工作,只是联系人让我很难过,所以我想我已经正确设置了API&credentials。在

我在API安全性中的“一个或多个API作用域”中添加了https://www.google.com/m8/feeds/,但这似乎没有帮助。在

我可能会错过什么?在


Tags: selfcomclienttokenapiaccessdefusername