google.api.client 从文件中获取空值

google.api.client get null from file

我正在尝试从 google 驱动器中的现有文件中获取一些数据。搜索正确 returns 我得到了一些元数据,但是当我尝试获取文件的最后修改日期时,我得到了空值。我不明白
这是我的代码的一部分:

FileList result = null;
        try {
            result = mService.files().list()
                    .setQ("name = file.db and trashed = false")
                    .execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
 Log.d("Sync_drive", result);
 List<com.google.api.services.drive.model.File> files;
  if (result != null) {
  for (com.google.api.services.drive.model.File fileD : files) {
 dateModified = String.valueOf(fileD.getModifiedTime().getValue());
 gdid = fileD.getId();
 Log.d("Sync_drive", "id: " + gdid);
 }

结果:

Sync_drive: {"files":[{"id":"1jX2w7F0Pjx28ug0lvjEIp4Kje6fw5JyF","kind":"drive#file","mimeType":"application/octet-stream","name":"file.db"}],"incompleteSearch":false,"kind":"drive#fileList"}

进程:PID:27987 java.lang.NullPointerException: 尝试在空对象引用上调用虚拟方法 'long com.google.api.client.util.DateTime.getValue()'

您首先需要连接到 google 客户端: 这是一个例子:

protected synchronized void buildGoogleApiClient() {
        if (checkPlayServices()) {
                    .requestServerAuthCode(BuildConfig.GOOGLE_WEB_CLIENT_ID)
                    .requestEmail()
                    .build();
            // Build a GoogleApiClient with access to the Google Sign-In API and the
            // options specified by gso.
            mGoogleApiClient = new GoogleApiClient.Builder(this)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .addApi(/*Api for google Drive*/)
                    .enableAutoManage(this, this)
                    .build();
            mGoogleApiClient.connect();

        }
    }

您还必须在同一个 activity 中实现回调函数: , GoogleApiClient.OnConnectionFailedListener, GoogleApiClient.ConnectionCallbacks

一旦客户端连接上,您就可以从文件中获取数据