【发布时间】:2016-06-24 14:11:56
【问题描述】:
我在本地机器上的 Java 开发服务器 (AKA devserver) 上运行了一个 GAE 应用程序,它定义了一些任务队列拉取队列。
我想使用在我的机器上运行的另一个独立 Java 应用程序中的任务队列 REST API 来访问这些拉取队列。
我尝试了 Google 的 documentation 建议的 the sample,它实现了租赁任务。显然,它使用了Google API Client Library for Java,它需要client_secrets.json 格式的文件:
{
"installed": {
"client_id": "retrieved from creating a Service Account for the project",
"client_secret": "supposedly appears in the JSON file that's downloaded upon creation of a Service Account for the project"
}
}
我为该项目创建了一个服务帐户,并自动下载了一个 JSON,格式如下:
{
"type": "service_account",
"project_id": "myProjectId",
"private_key_id": "some long hexadecimal",
"private_key": "an even longer encrypted stuff",
"client_email": "myServiceAccountName@myProjectId.iam.gserviceaccount.com",
"client_id": "a decimal number",
"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/myServiceAccountName%40myProjectId.iam.gserviceaccount.com"
}
在我的client_secrets.json 文件中,我使用private_key_id 作为client_secret 值并执行了示例代码。
结果是它在我的浏览器中打开了https://accounts.google.com/o/oauth2/auth,它显示了一个错误,状态码为400,并显示以下消息:
错误:redirect_uri_mismatch 应用程序:我的应用程序重定向 请求中的 URI:http://localhost:61130/Callback 不匹配 注册的重定向 URI。
我尝试了Taskqueue.Builder.setRootUrl("http://localhost:8080"),尽管它的 javadoc 说不要乱用它。它返回了401 Unauthorized。
- 有没有办法使用独立 Java 应用程序中的任务队列 REST API 来访问这些拉取队列?我更喜欢使用 Google 提供的 Java 库,但显然它们会自动指向实际的 GAE 服务。
- 当我确实想从云端的 Google App Engine 租用任务时,我应该使用什么作为
client_secrets.json文件中client_secret1 的值?
1 创建服务帐户时,由于我不是项目的所有者,因此收到以下消息:
无法将服务帐号添加到此项目的权限中 因为您不是该项目的所有者。提供服务 帐户访问此项目,请项目所有者将其添加到 项目权限。
我想知道这是否与自动下载的 JSON 中缺少 client_secret 属性有关。
【问题讨论】:
-
哇 6 小时和 3 次查看,使用任务队列 REST API 的人并不多……难怪,如果您不能在本地计算机上轻松使用它进行开发。
标签: java google-app-engine google-api-java-client task-queue