我正在尝试使用Android应用和Drive API以编程方式在驱动器上创建文件,然后建立公共链接。我设法制作了文件,但getWebViewLink,getAlternateLink,getEmbedLink始终返回null。我找不到答案,也没有找到任何有用的文档。
我的代码:
private GoogleSignInClient buildGoogleSignInClient() {
GoogleSignInOptions signInOptions =
new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(Drive.SCOPE_APPFOLDER)
.requestServerAuthCode(AUTH_CODE)
.build();
return GoogleSignIn.getClient(this, signInOptions);
}
private void createFile() {
final Task<DriveFolder> rootFolderTask = mDriveResourceClient.getRootFolder();
final Task<DriveContents> createContentsTask = mDriveResourceClient.createContents();
Tasks.whenAll(rootFolderTask, createContentsTask)
.continueWithTask(task -> {
DriveFolder parent = rootFolderTask.getResult();
DriveContents contents = createContentsTask.getResult();
OutputStream outputStream = contents.getOutputStream();
try (Writer writer = new OutputStreamWriter(outputStream)) {
writer.write("Hello World 1!");
}
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle("HelloWorld 1.txt")
.setMimeType("text/plain")
.setStarred(true)
.build();
return mDriveResourceClient.createFile(parent, changeSet, contents);
})
.addOnSuccessListener(this,
driveFile -> {
Log.d(TAG, "file created");
getMetaData(driveFile);
})
.addOnFailureListener(this, e -> {
Log.e(TAG, "Unable to create file", e);
});
}
private void getMetaData(DriveFile driveFile) {
Task<Metadata> metadataTask = mDriveResourceClient.getMetadata(driveFile);
metadataTask
.addOnSuccessListener(this,
metadata -> {
Log.e(TAG, "metadata.getWebViewLink() " + metadata.getWebViewLink());
})
.addOnFailureListener(this, e -> {
Log.d(TAG, "Unable to retrieve metadata", e);
});
}
答案 0 :(得分:0)
您可以参考此link。建议在const TicketPurchaseSchema = new Schema({
user: {type: Schema.Types.ObjectId, ref: 'User'},
event: {type: Schema.Types.ObjectId, ref: 'Event'},
tickets: [{type: Schema.Types.ObjectId, ref: 'Ticket'}],
time_stamp: {type: Date}
});
属性中添加for(var x of ticketPurchase.tickets){
//console.log(x);
if(x.id === ticket_id && x.validated === 'false'){
console.log('ticket not validated. Update');
TicketPurchase.update(
{_id: ticket_purchase_id, 'tickets._id': ticket_id},
{'$set':{
'tickets.$.validated': 'true'
}},
function (err){
console.log('updated validated');
if(err){console.log(err);}
}
);
Event
.update({_id: event_id, "tickets._id": x.id},
{$inc : {"tickets.$.total_quantity" : -1}});
console.log('updated ticket.total_qty');
payload['success'] = 'true';
}else if(x.id === ticket_id && x.validated === 'true'){
console.log('ticket validated');
payload['success'] = 'false';
payload['message'] = 'Ticket already validated.';
}
}
。
webViewLink