我正在尝试从google驱动器中的现有文件中获取一些数据。搜索正确地返回了一些元数据,但是当我尝试获取文件的最后修改日期时,我得到null。我不明白 这是我的代码的一部分:
const async = require('async'); // async node module : npm install --save async
Test.aggregate([
{$match: {'ownerid': req.body.ownerid}},
{$unwind: '$groupname'},
{$project: {_id:1, groupname :"$groupname"}}
], function(error, data){
if(error) {
console.log(error);
} else {
//Use async module instead of simple javascript loop
var primaryfilter = {'userid': req.body.ownerid};
var activityname = 'Group Owned';
async.eachSeries(data, function(dataItem, asyncCallback){
var secondaryfilter = { "groupowned" : { 'groupid': dataItem._id, 'groupname': dataItem.groupname } };
Test1.update(primaryfilter, {$push: secondaryfilter}, function(error, result){
if (error) {
asyncCallback(error);
} else {
asyncCallback();
}
});
}, function(err){
if(err) {
return res.send({"error":"true", "status":"500", "message":"Oops! Some error occurred while updating the "+activityname+" on Post"});
}
return res.send({"error":"false", "status":"201", "message":"Successfully Updated "+activityname+" on Post"});
});
}
});
结果:
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);
}
和
过程:PID:27987 java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法'long com.google.api.client.util.DateTime.getValue()'
答案 0 :(得分:0)
首先需要连接到谷歌客户端: 这是一个例子:
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();
}
}
您还必须在同一个活动中实现回调函数: ,GoogleApiClient.OnConnectionFailedListener,GoogleApiClient.ConnectionCallbacks
连接客户端后,您可以从文件中获取数据