I'm trying to use REST API to access tasks in a pull queue that I have
But I am continuously getting a 401 Unauthorized

The code I am using is listed below
import java.io.IOException;
import java.util.List;

import com.google.api.client.auth.oauth2.BearerToken;
import com.google.api.client.auth.oauth2.Credential.AccessMethod;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.taskqueue.Taskqueue;
import com.google.api.services.taskqueue.model.Task;
import com.google.api.services.taskqueue.model.Tasks;

public class Puller {

public static void main(String[] args) throws IOException {
Taskqueue tqFacade = new Taskqueue(HTTPTRANSPORT, JSONFACTORY, new
Tasks tasks = tqFacade.tasks().lease("s~ankitkhandelwal6test",
"default", 1, 300).execute();
List<Task> listOfTasks = tasks.getItems();
for(Task task: listOfTasks){

static class AuthHeaderAdder implements HttpRequestInitializer{

private String accessToken;

AuthHeaderAdder(String accessToken){
this.accessToken = accessToken;
public void initialize(HttpRequest req) throws IOException {
AUTH_HDR_ACCESS_METHOD.intercept(req, accessToken);


private static final AccessMethod AUTH_HDR_ACCESS_METHOD =
static HttpTransport HTTPTRANSPORT = new NetHttpTransport();
static JsonFactory JSONFACTORY = new JacksonFactory();

I am using the access token I received for client ID i created in google
api console. The same client email ID I have added to the queue.xml ACL as
I can access the taskqueue using standalone api explorer as well, but not
via java code.

Please guide.
Thanks in advance.

You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-appengine/-/G1Qrt9Du2BoJ.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to google-appengine+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 1 | next ›
Discussion Overview
groupgoogle-appengine @
postedJan 8, '13 at 5:53p
activeJan 8, '13 at 5:53p

1 user in discussion

Ankit khandelwal: 1 post



site design / logo © 2022 Grokbase