Reputation: 9255
I have a GAE app running on the Java Development Server (AKA devserver) on my local machine that defines some Task Queue pull queues.
I want to use the Task Queue REST API from a different standalone Java app, running on my machine, to access these pull queues.
I tried the sample suggested by Google's documentation that implements leasing tasks. Apparently, it uses the Google API Client Library for Java that requires a client_secrets.json
file of the format:
{
"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"
}
}
I created a Service Account for the project and a JSON was automatically downloaded, with the following format:
{
"type": "service_account",
"project_id": "myProjectId",
"private_key_id": "some long hexadecimal",
"private_key": "an even longer encrypted stuff",
"client_email": "[email protected]",
"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"
}
In my client_secrets.json
file I used private_key_id
as the client_secret
value and executed the sample code.
The result was that it opened https://accounts.google.com/o/oauth2/auth
in my browser, which displayed an error with status code 400
and the following message:
Error: redirect_uri_mismatch Application: My Application The redirect URI in the request: http://localhost:61130/Callback did not match a registered redirect URI.
I tried Taskqueue.Builder.setRootUrl("http://localhost:8080")
, although its javadoc says not to mess with it. It returned 401 Unauthorized
.
client_secret
1 in the client_secrets.json
file when I do want to lease tasks from Google App Engine on the cloud?1 When I created the Service Account, since I'm not the owner of the project, I got the following message:
The service account could not be added to this project's permissions because you are not an owner of the project. To give the service account access to this project, ask a project owner to add it to the project permissions.
I wonder whether this has something to do with the absence of a client_secret
property in the automatically downloaded JSON.
Upvotes: 0
Views: 379
Reputation: 6566
I don't think the dev server will expose the Task Queue API, do your tests against a separate test project that you create.
You can use the JSON from the service account to connect to the Task Queue API, see service accounts documentation.
GoogleCredential credential = GoogleCredential.fromStream(new FileInputStream("MyProject-1234.json")) .createScoped(Collections.singleton("https://www.googleapis.com/auth/taskqueue"));
Taskqueue taskQueue = new Taskqueue.Builder( httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME) .setTaskqueueRequestInitializer(new TaskqueueRequestInitializer() { @Override public void initializeTaskqueueRequest(TaskqueueRequest request) { request.setPrettyPrint(true); } }).build();
// get queue
com.google.api.services.taskqueue.model.TaskQueue queue = getQueue(taskQueue); System.out.println(queue);
// lease, execute and delete tasks
Tasks tasks = getLeasedTasks(taskQueue);
Upvotes: 0