javaee-esprit / google-api-java-client

Automatically exported from code.google.com/p/google-api-java-client
0 stars 0 forks source link

Drive.file().get(key) fails with spreadsheet keys from google-apps-script #859

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Version of google-api-java-client (e.g. 1.15.0-rc)?

v2-rev82-1.15.0-rc

Java environment (e.g. Java 6, Android 2.3, App Engine)?

App-Engine

Describe the problem.

Was working fine, then stopped working.

        Drive driveService = new Drive.Builder(TRANSPORT, JSON_FACTORY, credential).setApplicationName("CellMaster.com.au").build();
        File file = driveService.files().get(this.spreadsheetKey).execute();

Just noticed it now fails. I think it broke sometime in the last week or so. It 
fails with the execute(), it produces a 404 error. It gives the error when I 
use with the short spreadsheetKey that is produced by google apps script. The 
key produced by this google-apps-script code:

   SpreadsheetApp.getActiveSpreadsheet().getId();

But it works fine with a manual copy of the spreadsheet key from the url, such 
as
https://docs.google.com/spreadsheet/ccc?key=0AkGlO9jJLGO8dHJrSE0wTEF2VXRSdGRlNVQ
aaVRad0E

Note: the error is happening with old style spreadsheets, the 400,000 cell 
spreadsheets. I am not using the new style as they don't support GData yet.

How would you expect it to be fixed?

I don't want getting the key to be a manual process. So hopping you will make 
it work again. I suspect this stopped working in the last week, but the last 
time I am sure it worked was about be about 3 weeks ago.

Original issue reported on code.google.com by InstantW...@gmail.com on 17 Feb 2014 at 7:18

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Workaround:
in google apps script:  "var driveid = file.getId();" gives the long 
spreadsheet key that is in the URL

var ss = SpreadsheetApp.create("Test");
var id = ss.getId();
Logger.log(id)
// get the ss file through Drive using spreadsheet id
var file = DriveApp.getFileById(id);
var driveid = file.getId();
Logger.log(driveid)
// open the spreadsheet using id of file
var ssfromdrive = SpreadsheetApp.openById(driveid);
Logger.log(ssfromdrive.getName())

http://stackoverflow.com/questions/21842456/get-the-spreadsheet-key-that-is-in-t
he-url-not-ss-getid

Original comment by InstantW...@gmail.com on 3 Mar 2014 at 11:58

GoogleCodeExporter commented 9 years ago
This "workaround" doesn't avoid the "manual process" that the OP wanted to 
avoid.  In the example's case, you are getting the ID from a .create method, 
but what about files that already exist?  It seems now you have to first 
retrieve the user's list of spreadsheet files, and then parse out the key from 
that list.  Is there a "best" practice for retrieving the key of a google 
spreadsheet?

Original comment by dr.aries...@gmail.com on 23 Apr 2014 at 1:44