有没有办法将刷新令牌与 Google 目录服务 API 一起使用?我找不到任何示例(我正在使用 Python)。我正在寻找类似于以下代码的内容(这适用于 Google Adwords API),并具有预先设置的凭据:
oauth2_client = oauth2.GoogleRefreshTokenClient(
CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN)
adwords_client = adwords.AdWordsClient(
DEVELOPER_TOKEN, oauth2_client, USER_AGENT, CLIENT_CUSTOMER_ID)
self.managed_customer_service = adwords_client.GetService(
'ManagedCustomerService', version='v201402')
对于 Directory API,我只找到了以下代码片段,但我不知道如何使用刷新令牌:
flow = OAuth2WebServerFlow(CLIENT_ID, CLIENT_SECRET, OAUTH_SCOPE, REDIRECT_URI)
authorize_url = flow.step1_get_authorize_url()
print 'Go to the following link in your browser: ' + authorize_url
code = raw_input('Enter verification code: ').strip()
credentials = flow.step2_exchange(code)
# Create an httplib2.Http object and authorize it with our credentials
http = httplib2.Http()
http = credentials.authorize(http)
self.directory_service = build('admin', 'directory_v1', http=http)
我的最终目标是仅使用刷新令牌授权我的应用程序,而无需每次打开浏览器、登录并获取新令牌。