Hello,
I'm trying to use REST API to access tasks in a pull queue that I have
created.
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
AuthHeaderAdder(args[0]));
Tasks tasks = tqFacade.tasks().lease("s~ankitkhandelwal6test",
"default", 1, 300).execute();
List<Task> listOfTasks = tasks.getItems();
for(Task task: listOfTasks){
System.out.println(task.toPrettyString());
}
}
static class AuthHeaderAdder implements HttpRequestInitializer{
private String accessToken;
AuthHeaderAdder(String accessToken){
this.accessToken = accessToken;
}
@Override
public void initialize(HttpRequest req) throws IOException {
AUTH_HDR_ACCESS_METHOD.intercept(req, accessToken);
}
}
private static final AccessMethod AUTH_HDR_ACCESS_METHOD =
BearerToken.authorizationHeaderAccessMethod();
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
well.
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.