【发布时间】:2015-11-28 07:39:48
【问题描述】:
我正在为一家公司开发一个应用,我需要将它与 Google 云端硬盘集成。我不能使用本机 API,因为公司有需要处理的不是由应用程序创建的文件,我需要完整的驱动器范围,所以我必须使用 REST API。
问题来了,因为我对 JSON 和 REST 只有非常基本的了解,所以这些教程对我来说还不够基础。
教程:https://developers.google.com/drive/web/integrate-create
据我了解,我需要在我的 Java 代码中创建 JSON,然后通过示例代码传递它?
JSON
{
"action":"create",
"folderId":"0ADK06pfg",
"userId":"103354693083460731603"
}
JAVA
public class State {
/**
* Action intended by the state.
*/
public String action;
/**
* IDs of files on which to take action.
*/
public Collection<String> ids;
/**
* Parent ID related to the given action.
*/
public String parentId;
/**
* Empty constructor required by Gson.
*/
public State() {}
/**
* Create a new State given its JSON representation.
*
* @param json Serialized representation of a State.
*/
public State(String json) {
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
State other = gson.fromJson(json, State.class);
this.action = other.action;
this.ids = other.ids;
this.parentId = other.parentId;
}
}
问题是我不知道如何创建 JSON,也不太了解如何在创建时使用 JSON 来执行创建文件和查询文件等操作。
如果有人可以让我在用户根文件夹中创建一个空文件,那么我可能可以从那里获取它,但我真的可以朝正确的方向轻推!
【问题讨论】:
标签: android json rest google-drive-api google-drive-android-api