【发布时间】:2016-05-12 20:09:37
【问题描述】:
我有一个使用远程 api 从我的 appengine 数据存储中提取数据的周期性工作。 这份工作突然停止工作,因为谷歌决定不再喜欢我的服务器了。 不过,它可以在我的机器上运行。
以下是我机器上的 python shell 中发生的情况:
$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from google.appengine.ext.remote_api import remote_api_stub
>>> app = 'qmagicobr2.appspot.com'
>>> remote_api_stub.ConfigureRemoteApiForOAuth(app, '/_ah/remote_api')
<google.appengine.tools.appengine_rpc_httplib2.HttpRpcServerOAuth2 object at 0x7f5cdfac61d0>
>>>
这就是我的服务器上的相同代码会发生什么
(qmbi)dashboard@ip-172-31-32-222:~/qmbi$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from google.appengine.ext.remote_api import remote_api_stub
>>> app = 'qmagicobr2.appspot.com'
>>> remote_api_stub.ConfigureRemoteApiForOAuth(app, '/_ah/remote_api')
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:
当我转到上面的 URL 时,我得到一个错误页面,上面写着:
- 这是一个错误。 错误:invalid_client 未找到 OAuth 客户端。 请求详细信息 access_type=离线 范围=https://www.googleapis.com/auth/appengine.apishttps://www.googleapis.com/auth/userinfo.email response_type=代码 redirect_uri=urn:ietf:wg:oauth:2.0:oob client_id=无 这就是我们所知道的。
帮助?
---- 更新 (2016-05-12) -----
我忘了提及我正在使用的身份验证文件。
要使ConfigureRemoteApiForOAuth 工作,我需要有一个环境变量GOOGLE_APPLICATION_CREDENTIALS 指向凭据文件。
我愿意。
在两种环境中(我的机器和服务器)GOOGLE_APPLICATION_CREDENTIALS 指向一个 json 文件(两种环境中的相同文件),格式如下:
{
"type": "service_account",
"project_id": "qmagicobr2",
"private_key_id": "000000000000000000000000000000000000000",
"private_key": "-----BEGIN PRIVATE KEY-----\nAAAAAAAAAAAAAAAAAAAAAAA....AAAA\n-----END PRIVATE KEY-----\n",
"client_email": "dashboard@qmagicobr2.iam.gserviceaccount.com",
"client_id": "0000000000000000000000",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/dashboard%40qmagicobr2.iam.gserviceaccount.com"
}
此文件是使用 Appengine 的开发者控制台生成的,位于“凭据/服务帐户密钥/管理服务帐户”下
【问题讨论】:
标签: python google-app-engine oauth-2.0