【发布时间】:2020-08-29 08:32:51
【问题描述】:
我尝试在正文(data)中发送权限类型字段,但没有成功。
文档说明:在body上发送权限和角色。
文档链接:https://developers.google.com/drive/api/v3/reference/permissions/create
我得到了这个答案。
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "The permission type field is required.",
"locationType": "other",
"location": "permission.type"
}
],
"code": 400,
"message": "The permission type field is required."
}
}
这是我的代码结构,我将不胜感激。
const file = this.file;
var FileID = "16omyu1bxFk1tVVMrpIcYQDC3sNYxSIg2";
const fr = new FileReader();
fr.readAsDataURL(file);
fr.onload = function() {
const boundary = "xxxxxxxxxx";
let data = "--" + boundary + "\n";
data += "Content-Type: application/json; charset=UTF-8\n\n";
data += JSON.stringify({role: "reader", type: "anyone"}) + "\n";
$.ajax({
type: "POST",
beforeSend: function(request) {
request.setRequestHeader("Authorization", "Bearer" + " " + localStorage.getItem("accessToken"));
request.setRequestHeader("Content-Type", "boundary=" + boundary);
},
url: "https://www.googleapis.com/drive/v3/files/" + FileID + "/permissions",
success: function (data) {
console.log(data);
},
error: function (error) {
console.log(error);
},
async: true,
data: data,
cache: false,
processData: false,
timeout: 60000
});
}
【问题讨论】:
标签: javascript google-drive-api