【发布时间】:2014-11-13 02:55:17
【问题描述】:
已编辑
这可能是一个愚蠢的问题,但我无法弄清楚。我在 Eclipse 中使用 Java 和 GWT 来创建一个 RPC 应用程序来获取谷歌驱动器元数据。一切正常(我在服务器端取回元数据),但我不知道如何将这些数据传递到客户端以便我可以显示它。
我正在获取 google drive 文档的元数据列表,如下所示:
public List<File> getFromRemoteServer()
throws HowToListingException {
List<File> lista = null;
try {
lista = retrieveAllFiles(getDriveService("email@xxxx.org"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (GeneralSecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return lista;
}
我的问题是,如何将 List 类型更改为客户端可以使用的类型?即我在这里放什么(填空)?以及如何将 lista 转换为该类型?
asyncSvc.getFromRemoteServer( {
new AsyncCallback<____________>() {
}
希望更多地澄清信息:
我知道要完成这项工作,我必须序列化 File 对象。我只是不确定我是否可以或将其放在哪里。 http://www.gwtproject.org/doc/latest/tutorial/RPC.html#serialize
在服务器端实现中,我使用的是这个文件:
导入 com.google.api.services.drive.model.File;
我需要使用它来让这段代码正常工作:
public static Drive getDriveService(String userEmail) throws GeneralSecurityException,
IOException, URISyntaxException {
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(Arrays.asList(DriveScopes.DRIVE))
.setServiceAccountUser(userEmail)
.setServiceAccountPrivateKeyFromP12File(
new java.io.File(SERVICE_ACCOUNT_PKCS12_FILE_PATH))
.build();
Drive service = new Drive.Builder(httpTransport, jsonFactory, null)
.setHttpRequestInitializer(credential).build();
return service;
}
private static List<File> retrieveAllFiles(Drive service) throws IOException {
List<File> result = new ArrayList<File>();
Files.List request = null;
try {
request = service.files().list();
FileList files = request.setQ("'"+"0B9lpwZZfxxxxxxxxVeEJFR3M"+"' in parents and trashed=false").execute();
result.addAll(files.getItems());
request.setPageToken(files.getNextPageToken());
}
catch (IOException e)
{
System.out.println("An error occurred: " + e);
request.setPageToken(null);
}
for(File f:result)
{
System.out.println(f.getTitle());
System.out.println(f.getOwners());
System.out.println(f.getModifiedDate());
}
return result;
}
当我尝试使用时问题来了
import com.google.api.services.drive.model.File;
在客户端的同步和异步接口和客户端代码(入口点)。我收到有关“您是否忘记继承所需模块 - 找不到此导入的代码”的错误消息。我假设这意味着我不能在客户端使用它。我尝试导入 java.io.File ,但随后收到无法在两种类型之间转换的消息。
我觉得我已经很接近了,我只需要朝着正确的方向前进。任何帮助表示赞赏。
【问题讨论】:
标签: java gwt google-drive-api