我在android中拥有自己的帐户google-drive实现。我必须完成授权过程(https://developers.google.com/drive/web/service-accounts),然后尝试将文件上传到Google云端硬盘。一些使用令牌上传它的教程。但我不知道从哪里获取token_id来驱动" Drive"。我是android开发的新手,所以。如果有任何想法,请告诉我。
先谢谢
我试过这个:
授权流程
try
{
System.out.println("HARDCODE CREDENTIALS here");
credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(DriveScopes.DRIVE)
.setServiceAccountPrivateKeyFromP12File(tempPkc12File)
.build();
}
catch (GeneralSecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Drive service = new Drive.Builder(httpTransport, jsonFactory, null)
.setHttpRequestInitializer(credential)
.setApplicationName("Sample Owned Account")
.build();
final File body = new File();
body.setTitle("My document");
body.setDescription("A test document saf hkfhflkhs;lkhlf h;ls;afhsa;lk");
body.setMimeType("text/plain");
java.io.File fileContent = new java.io.File("document.txt");
final FileContent mediaContent = new FileContent("text/plain", fileContent);
Thread thread = new Thread()
{
@Override
public void run()
{
try {
File file = service.files().insert(body, mediaContent).execute();
System.out.println("File ID: " + file.getId());
} catch (Exception e) {
e.printStackTrace();
}
}
};
thread.start();