5

I am trying to download the Google spreadsheet using download API version 3 ( v3 ). I am getting "java.lang.IllegalArgumentException: Trying to set foreign cookie" error message while downloading spreadsheet. I am tried by my google apps account which is authenticated by 2 legged oauth authentication process. Is there anyone facing this kind of problem ?

Here is the error stacktrace :

Servlet.service() for servlet action threw exception|java.lang.IllegalArgumentException: Trying to set foreign cookie
    at com.google.gdata.client.http.GoogleGDataRequest$GoogleCookie.<init>(GoogleGDataRequest.java:166)
    at com.google.gdata.client.http.GoogleGDataRequest$GoogleCookieHandler.put(GoogleGDataRequest.java:399)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:710)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1000)
    at sun.net.www.protocol.http.HttpURLConnection.getHeaderFields(HttpURLConnection.java:2053)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getHeaderFields(HttpsURLConnectionImpl.java:263)
    at com.google.gdata.client.http.HttpGDataRequest.isOAuthProxyErrorResponse(HttpGDataRequest.java:558)
    at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:549)
    at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530)
    at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)

Edit: This issue occurs only in one of our user's accounts using our App. Its working fine for all other users

Barani
  • 552
  • 4
  • 18
  • How do you setup the service. The OAuth2 etc. Can you paste some code. For the OAuth2, the Google DrEdit example was a good starting point. For the spreadsheet API this example covers most of it: https://gdata-java-client.googlecode.com/svn-history/r51/trunk/java/sample/spreadsheet/cell/CellDemo.java – eddyparkinson Mar 12 '14 at 03:10
  • I am using 2 legged oauth setup. Sample code : docsService = new DocsService(domain); GoogleOAuthParameters oauthParam = new GoogleOAuthParameters(); oauthParam.setOAuthConsumerKey(consumerKey); oauthParam.setOAuthType(OAuthParameters.OAuthType.TWO_LEGGED_OAUTH); oauthParam.setOAuthConsumerSecret(consumerSecret); OAuthHmacSha1Signer signer = new OAuthHmacSha1Signer(); oauthParam.setScope("https://docs.google.com/feeds/"); docsService.setOAuthCredentials(oauthParam, signer); – Barani Mar 12 '14 at 09:59
  • Is the problem the OAuth token or the Spreadsheet service? I added details of how I setup the service. – eddyparkinson Mar 12 '14 at 23:42
  • A post on 2 legged oauth2 http://stackoverflow.com/questions/14250383/how-does-2-legged-oauth-work-in-oauth-2-0 – eddyparkinson Mar 12 '14 at 23:44

2 Answers2

2

I faced the same issue and was able to solve it by changing the url.

The URL I got directly from GDrive:

https://docs.google.com/spreadsheets/d/19Du6mgmzP94vxxHK5httgfK4dqgycQkBBLDq_6I5J7o/edit#gid=1472457471

Had to modify the above to:

https://spreadsheets.google.com/feeds/spreadsheets/**19Du6mgmzP94vxxHK5httgfK4dqgycQkBBLDq_6I5J7o

Hope this will help someone.

Rafa Viotti
  • 9,998
  • 4
  • 42
  • 62
AChamara
  • 21
  • 2
0

I get the service this way:

        int GDATA_TIMEOUT = 10* 1000;   
        spreadsheetService = new SpreadsheetService("cellmaster.com.au-v0.2");

        spreadsheetService.setHeader("Authorization", "Bearer " + accessToken);

        spreadsheetService.setConnectTimeout(GDATA_TIMEOUT);
        spreadsheetService.setReadTimeout(GDATA_TIMEOUT);

And include a retry loop because it does fail once in a while.

eddyparkinson
  • 3,680
  • 4
  • 26
  • 52