使用jquery,我已经管理到目前为止发送了一个Copy Item请求(POST / me / drive / items // copy), 但是如果我尝试添加权限(POST / drive / items // invite),我会收到" Unsupported段类型"错误。
API文档: graph.microsoft.io/en-us/docs/api-reference/v1.0/api/item_invite
(我复制了两个比较功能)
// working:
copyFile:function(id, folderId){
// https://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/item_copy
// POST /me/drive/items/<id>/copy
var endpointUrl = 'https://graph.microsoft.com/v1.0/me/drive/items/'+id+'/copy';
var data={};
data.parentReference={'id':folderId}
$.ajax({
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("Content-Type","application/json");
xhrObj.setRequestHeader("Accept","application/json");
},
processDate: false,
datatype : "json",
method: "POST",
//http://stackoverflow.com/questions/13956462/jquery-post-sends-form-data-and-not-json
data: JSON.stringify(data),
url: endpointUrl,
contentType : 'application/json',
headers : { "authorization" : "Bearer " + token }
}).success(function(data) {
alert('success!')
});
},
///NO WORKING ?
invite:function(id, user){
// http://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/item_invite
// POST /drive/items/<id>/invite
var endpointUrl = 'https://graph.microsoft.com/v1.0/drive/items/'+id+'/invite';
data={
"requireSignIn": true,
"sendInvitation": false,
"roles": "read",
"recipients": [ { "email": user }],
"message": "NO MESSAGE ?"
}
$.ajax({
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("Content-Type","application/json");
xhrObj.setRequestHeader("Accept","application/json");
},
datatype : "json",
method: "POST",
data: JSON.stringify(data),
url: endpointUrl,
contentType : 'application/json',
headers : {"authorization" : "Bearer " + token}
}).success(function(data) {
alert( 'success!')
});
API返回:
{
"error": {
"code": "BadRequest",
"message": "Unsupported segment type. ODataQuery: drive/items/***********/invite",
"innerError": {
"request-id": "********",
"date": "2016-09-14T09:01:32"
}
}
}
我错过了什么吗?
答案 0 :(得分:1)
似乎v1.0版本目前无效。我用这个网址交换了测试版:
var endpointUrl = 'https://graph.microsoft.com/beta/me/drive/items/'+id+'/invite';
它有效