0

I am using Google Tasks API and also Gogole Adwords API....To use Adwords API i have to use latest google-http-client jar...but when I use the latest jar, Tasks API doesnt seems to work. Here is the code I am using for tasks

      HttpTransport httpTransport = new NetHttpTransport();
      JacksonFactory jsonFactory = new JacksonFactory();
      OAuthHmacSigner signer = new OAuthHmacSigner();
      signer.clientSharedSecret = consumerSecret;
      GoogleOAuthDomainWideDelegation initializer = new GoogleOAuthDomainWideDelegation();
      initializer.requestorId = "jags@solutiontest.com"; // email of the user, basically the xoauth_requestor_id URL param
      OAuthParameters parameters = new OAuthParameters();
      parameters.consumerKey=consumerKey;
      parameters.version = "1";
      parameters.signer = signer;
      initializer.parameters = parameters;
      Tasks service = Tasks.builder(httpTransport, jsonFactory).setHttpRequestInitializer(initializer).build();

      Tasklists.List listTask = service.tasklists().list();
      TaskLists taskLists = listTask.execute();

Here is the complete stacktrace for the error

java.lang.NoSuchMethodError: com.google.api.client.http.HttpRequest.setAllowEmptyContent(Z)Lcom/google/api/client/http/HttpRequest; at com.google.api.client.googleapis.services.GoogleClient.buildHttpRequest(GoogleClient.java:171) at com.google.api.client.http.json.JsonHttpRequest.buildHttpRequest(JsonHttpRequest.java:179) at com.google.api.client.http.json.JsonHttpRequest.executeUnparsed(JsonHttpRequest.java:207) at com.google.api.services.tasks.Tasks$Tasklists$List.execute(Tasks.java:1731)

What should I do in-order to use both Google Tasks and Google Adwords API? Any pointers will be grateful..

TIA,
VijayRaj

VijayRaj
  • 425
  • 1
  • 4
  • 22

1 Answers1

0

This issue is unrelated to the Tasks API. Luckily, it's an easy fix. The method you are trying to call, setAllowEmptyContent, was deprecated in version 1.11 and removed in 1.12. You're getting a NoSuchMethodError because the method simply does not exist in the client library jar you're using.

As per the javadoc on that method from version 1.11, use the following instead:

setContent(new EmptyContent())

Here is the source and javadoc for that method as of version 1.11. You can see the relevant deprecation warning there.

Nick
  • 8,964
  • 4
  • 26
  • 37
  • As you can see the code, I am not using that method anywhere...may be it is called internally....Can you plz give me an example code or point to any link where I can find how to authenticate Tasks service object using the latest java client library? – VijayRaj Jul 01 '13 at 06:53
  • 1
    You're using a lot of old classes, such as OAuthHmacSigner and GoogleOAuthDomainWideDelegation which have not been a part of library since versions that are years old. I'm not really sure how you've set up your project, but the source code for the library is all open source. You should be able to download source jars and debug - walk through the code and see where the method is being called. – Nick Jul 01 '13 at 15:14
  • As for authenticating with the Tasks service, it is nearly identical to authenticating with many other Google services. Check out any of the library's [samples](https://code.google.com/p/google-api-java-client/source/browse?repo=samples) such as the [Calendar Sample](https://code.google.com/p/google-api-java-client/source/browse/calendar-cmdline-sample/src/main/java/com/google/api/services/samples/calendar/cmdline/CalendarSample.java?repo=samples#68) for examples of standard three-legged OAuth where the user is prompted to give the app permission – Nick Jul 01 '13 at 15:17
  • I am using all the latest jars and also gone through the document and the code mentioned in this link https://developers.google.com/google-apps/help/articles/2lo-in-tasks-for-marketplace#using .... but it seems the constructor for Tasks class which is used in the code is not available..That is the reason I am using the old libraries in order to make use of Tasks API ... – VijayRaj Jul 02 '13 at 06:54
  • But as I said, when using the old libraries, I am not able to work on Adwords API....and hence I want to move to new libraries... – VijayRaj Jul 02 '13 at 06:56
  • That linked article is very old (2011), and shows how to use the original OAuth spec. It's _highly_ recommended you use OAuth2.0, which is what's shown in most of the samples – Nick Jul 02 '13 at 16:35
  • Thanks for the help Nick.....I am using this code to authenticate Google Tasks service object with the latest jars and it seems to work fine.. – VijayRaj Jul 04 '13 at 07:10
  • OAuthHmacSigner signer = new OAuthHmacSigner(); signer.clientSharedSecret = consumerSecret; OAuthParameters initializer = new OAuthParameters(); initializer.version = "1"; initializer.consumerKey = consumerKey; initializer.signer = signer; Tasks service = new Tasks.Builder(httpTransport,jsonFactory, initializer).build(); Tasklists.List listTask = service.tasklists().list(); listTask.set("xoauth_requestor_id",loginUserEmailId);` – VijayRaj Jul 04 '13 at 07:11