“createFromResourceId()"在哪里?去? [英] Where did the "createFromResourceId()" go?
问题描述
我已更新到新版本的 Google Play Services 4.2(库版本 15).突然之间,对 DriveId.createFromResourceId("....") 的调用没有得到解决.
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");
我知道我可以使用 DriveId 或 encodeToString()/decodeFromString(),但是:
I know I can use either DriveId, or encodeToString() / decodeFromString() instead, but:
- ResourceId 直接对应 Google Drive 中文件的 http.
- 即使文件被操作也似乎是持久的
文档和demo code 广泛使用该方法.另外,镜像方法 getResourceId() 仍然存在.
不仅仅是一个问题,它是 Google Drive/ 的澄清请求Google Play Svcs 伙计们.
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.
推荐答案
我测试了 Burcu 的答案,不幸的是它没有奏效.或者也许我错误地表达了这个问题.我会尝试重新措辞(我找到了正确答案).
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).
DriveId 有 2 种不同的字符串类型 ID 表示(文件和文件夹).
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"
在 4.1 中,有 2 种方法可以将它们转回 DriveId
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());
它们都成对正常工作,我选择了 ResourceId 品种,因为这个短字符串出现在其他系统(Apps Script...)中使用的 http 地址中.例如:https://docs.google.com/file/d/UW2aFJfdajB3M3JENy00Ums0B1mQ
此外,即使文件在 Google 云端硬盘中被操作(已删除、恢复、移动),它也似乎是持久的.
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).
但在 4.2 中,createFromResourceId() 消失了,不能 被decodeFromString()"替换,如下所示:
But in 4.2, the createFromResourceId() disappeared and CAN NOT be replaced by "decodeFromString()" like this:
//INCORRECT
DriveId.decodeFromString(DriveId.getResourceId());
相反,必须通过以下方式检索 ResourceId 中的 DriveId:
Instead, the DriveId from ResourceId has to be retrieved this way:
DriveIdResult result = Drive.DriveApi.fetchDriveId(GAC, DriveId.getResourceId()).await();
DriveId drvID = result.getDriveId();
(为了简单起见,我使用await"版本).
(and I use the "await" version for simplicity).
所以结论是:createFromResourceId() 被替换为
So the conclusion is: The createFromResourceId() was replaced by
Drive.DriveApi.fetchDriveId(GAC, DriveId.getResourceId()).await().getDriveId()
需要注意的是,await()"构造应该作为普通 UI 线程中的回调来实现.
with the caveat that the "await()" construct should be implemented as a callback in normal UI thread.
更新(2014-10-23)
上面的答案很陈旧,请参考下面的评论.
The answer above is quite stale, please refer to the comments below.
这篇关于“createFromResourceId()"在哪里?去?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!