在Google云端硬盘Android API的元数据中设置说明

时间:2014-04-07 04:20:04

标签: google-drive-api google-drive-android-api

1 个答案:

答案 0 :(得分:1)

不幸的是,此刻,AFAIK。我现在所做的是初始化GDAA和RESTful API(参见'垃圾解决方案' SO 22295903),如下所示:

  private GoogleApiClient _gac;
  private com.google.api.services.drive.Drive _svc;
  public GoogleApiClient init(String email){
    _gac = new GoogleApiClient.Builder(UT.ACTX).addApi(com.google.android.gms.drive.Drive.API)
      .addScope(com.google.android.gms.drive.Drive.SCOPE_FILE).setAccountName(email).build();

    com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential crd =
     GoogleAccountCredential.usingOAuth2(UT.ACTX, 
                            Arrays.asList(com.google.api.services.drive.DriveScopes.DRIVE_FILE));
    crd.setSelectedAccountName(email);  
    _svc = new com.google.api.services.drive.Drive.Builder(
                            AndroidHttp.newCompatibleTransport(), new GsonFactory(), crd).build();
    return this;
  }

您可以从DGAA(上面的GoogleApiClient _gac)获取说明,但是像这样更新/写入RESTFul(关闭UI线程):

  public void oldDescUpW(String titl, String mime, String desc) {
    try {
      final FileList gLst = _svc.files().list()
         .setQ("title = '"+titl+".jpg' and mimeType = '"+mime+"' and trashed = false")
         .setFields("items(id)").execute();
      if (gLst.getItems().size() == 1) {
        final String sId = gLst.getItems().get(0).getId();
        com.google.api.services.drive.model.File body = 
                                                new com.google.api.services.drive.model.File();
        body.setDescription(desc);
      _svc.files().patch(sId, body).execute();
      }
    } catch (Exception e) {} 
  }    

也可以使用资源ID'来自GDAA来解决RESTful中的文件,但它并不总是立即可用(如果文件是在GDAA中创建的)。见SO 22874657

<强>声明:

这是一个HACK,不应该通过GDAA提供替代方案。