今天我的oauth令牌已过期,但我无法重新生成它。
我有一个命令行工具,可以与Google Cloud Platform上的数据存储进行交互,以执行一些支持任务。
以下是负责连接的代码行
from google.appengine.ext.remote_api import remote_api_stub
remote_api_stub.ConfigureRemoteApiForOAuth(app_name, '/_ah/remote_api')
打印出这些错误消息:
INFO:oauth2client.client:Attempting refresh to obtain initial access_token
INFO:oauth2client.client:Refreshing access_token
INFO:oauth2client.client:Failed to retrieve access token: {
"error" : "invalid_grant"
}
INFO:google.appengine.tools.appengine_rpc:Got access token error
Traceback (most recent call last):
File "/usr/local/google_appengine/google/appengine/tools/appengine_rpc_httplib2.py", line 247, in Send
url, method=method, body=payload, headers=headers)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/oauth2client/oauth2client/client.py", line 547, in new_request
self._refresh(request_orig)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/oauth2client/oauth2client/client.py", line 775, in _refresh
self._do_refresh_request(http_request)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/oauth2client/oauth2client/client.py", line 840, in _do_refresh_request
raise AccessTokenRefreshError(error_msg)
AccessTokenRefreshError: invalid_grant
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.apis+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&client_id=None&access_type=offline
Enter verification code:
然后是一个网址,它要求我在浏览器中打开。
当我将它复制并粘贴到chrome中时,我就得到了
所以我尝试再次运行gcloud auth login
。我授予了它所要求的所有访问权限。它似乎工作正常。
但是当重新运行我的命令行工具时,它会给出相同的错误消息。
那么如何重新生成此验证码'?
答案 0 :(得分:1)
这解决了我的问题
https://stackoverflow.com/a/40493992/58129
运行
gcloud auth application-default login --scopes=https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/userinfo.email