You need to authenticate natively your cordova application with Google in order to make use of the APIs. Firstly follow the official Google guides for each platform (iOS and Android) if you haven't already, to create the required credentials for your application. Then try the plugin on the link below:
Cordova google drive plugin
I created this plugin for a personal mobile project. This plugin supports upload,download and list of files.
To retrieve a list of files created/uploaded by your application for Android you can try this on Java side:
private void fileList() {
Query query = new Query.Builder().addFilter(Filters.and(
Filters.eq(SearchableField.MIME_TYPE, "application/octet-stream"),
Filters.eq(SearchableField.TRASHED, false))).build();
Drive.DriveApi.query(mGoogleApiClient, query)
.setResultCallback(new ResultCallback<DriveApi.MetadataBufferResult>() {
@Override
public void onResult(DriveApi.MetadataBufferResult result) {
if (!result.getStatus().isSuccess()) {
mCallbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR,"failed to retrieve file list"));
return;
}
MetadataBuffer flist = result.getMetadataBuffer();
Log.i(TAG,flist.get(0).getClass().getName());
JSONArray response = new JSONArray();
for (Metadata file: flist
) {
try {
response.put(new JSONObject().put("name", file.getTitle()).put("created", file.getCreatedDate().toString()).put("id", file.getDriveId().toString()));
}catch (JSONException ex){ex.getMessage();}
}
JSONObject flistJSON = new JSONObject();
try{
flistJSON.put("flist", response);
} catch (JSONException ex){}
mCallbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK,flistJSON));
flist.release();
//Log.i(TAG,flist.toString());
}
});
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…