Where Did the "Createfromresourceid()" Go

Where did the createFromResourceId() go?

I tested Burcu's answer, and unfortunately it did not work. Or maybe I phrased the question incorrectly. I'll try to re-phrase it (and I found the correct answer).

There are 2 different string type ID representations available for DriveId (both file and folder).

1/ DriveId.encodeToString(), resulting in something like:
"DriveId:CAESHDBCMW1RVVcyYUZKZmRhakIzMDBVbXMYjAUgssy8yYFRTTNKRU55"
2/ and DriveId.getResourceId(), resulting in shorter:
"UW2aFJfdajB3M3JENy00Ums0B1mQ"

In 4.1, there were 2 methods that would turn these back to the DriveId

1/ DriveId.decodeFromString(DriveId.encodeToString());
2/ DriveId.createFromResourceId(DriveId.getResourceId());

Both of them worked correctly in pairs and I chose the ResourceId variety, since this short string appears in http address used in other systems (Apps Script...). For example:
https://docs.google.com/file/d/UW2aFJfdajB3M3JENy00Ums0B1mQ

Also, it appears to be persistent even if the file is manipulated in Google Drive (trashed, restored, moved).

But in 4.2, the createFromResourceId() disappeared and CAN NOT be replaced by "decodeFromString()" like this:

//INCORRECT    
DriveId.decodeFromString(DriveId.getResourceId());

Instead, the DriveId from ResourceId has to be retrieved this way:

DriveIdResult result = Drive.DriveApi.fetchDriveId(GAC, DriveId.getResourceId()).await();
DriveId drvID = result.getDriveId();

(and I use the "await" version for simplicity).

So the conclusion is:
The createFromResourceId() was replaced by

Drive.DriveApi.fetchDriveId(GAC, DriveId.getResourceId()).await().getDriveId()

with the caveat that the "await()" construct should be implemented as a callback in normal UI thread.

UPDATE (2014-10-23)

The answer above is quite stale, please refer to the comments below.

Google Drive API Folder/Child ID

UPDATE (2015/09/01) Per 'BSEs' comment below.

Sorry, I assumed it is Android (being professionally distorted).
Anyway, to make sure, look at the ID string in question and compare it with the ID you get from drive.google.com > right click > Get link. You should see something like:

https://drive.google.com/open?id=0B1mqwertyasdfghZxCvbItM0E

If the id= string matches your resource ID, you're cool. Sorry for the confusion.

ORIGINAL (incorrect for .NET, applies to GooPlaySvcs/GDAA on Android)

I believe it does.

When testing the ResourceId availability here, I remember getting DriveId in one form immediately in the 'onResult()' callback. Later, when the 'onCompletion()' event occured, the DriveId of the same object looked very different (applies to both file and folder) .

Also, look at Daniel's comment here, it suggests that you should not rely on the value of the DriveId in any moment and use 'equals()'.

The ResourceId would be more appropriate ID to store, shuttle around, etc... DriveId is useless outside the GooPlaySvcs instance. And, based on some hints from Drive-Involved-Googlers, relying on a concrete value of DriveId is dangerous. That makes existence of 'encodeToString() / decodeFromString()' somewhat questionable, right?

Good Luck

Google Drive Android API - Access app-created files and folders across devices

You don't necessarily have to have the DriveId, its just the most sure-fire way to do it since it uniquely identifies the folder. You can also query based on the title to try to find the same folder. Assuming that the web and Android app share an app id, both should be able to access the same files.

One easy option for sharing state between apps is to make use of the newly launched App Folders (called App Data Folders on the web.) This is a hidden folder where you can store files specific to your app. Its not yet in the Android docs, but it should show up there as soon as the rollout of Google Play Services 4.3 is released. See http://android-developers.blogspot.com/2014/03/google-play-services-43.html

How to get DriveId of created folder in Google Drive Android API

If you have the metadata for the folder (or a DriveFolder object, from which you can get the metadata), you can just call getDriveId.

If you have the web resource, you can get the DriveId using that resource id using fetchDriveId

Cannot find DriveId. Are you authorized to view this file?: Even if EXISTING_FOLDER_ID is set manually

I do believe that 'result.getDriveFile().getDriveId()' gives you a 'DriveId', an ID used by GDAA only. The 'EXISTING_FILE_ID' refers to another ID, so called ResourceID. You have to use that one. See SO 21800257. The ResourceId is the original ID used in older RESTful API, and the only one that you can use when referring to the Drive object across different devices (DriveID is device specific). ResourceID can also be seen as a part of the URL address of the object.

BTW. the shortest answer to your question is:

result.getDriveFile().getDriveId().getResourceId();

But you may get NULL if you're too quick see SO 22874657 .

Good Luck.



Related Topics



Leave a reply



Submit