Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

android - Where did the "createFromResourceId()" go?

I have updated to the new version of Google Play Services 4.2 (library version 15). And suddenly, the calls to DriveId.createFromResourceId("....") are unresolved.

DriveId sFolderId = DriveId.createFromResourceId("0B2EE......N3J6RU0"); 

I know I can use either DriveId, or encodeToString() / decodeFromString() instead, but:

  1. ResourceId corresponds directly with a http of the file in Google Drive.
  2. Appears to be persistent even if the file is manipulated

Both the documentation and demo code uses the method extensively. Also, the mirror method getResourceId() is still in existence.
More than a question, it is a request for clarification from the Google Drive / Google Play Svcs folks.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...