2016-09-14 84 views
0

使用jQuery,我已經管理到目前爲止發送複製項目請求(POST /我/驅動器/項目//副本), 但是,如果我嘗試添加權限(POST /驅動器/項目//邀請),我收到「不支持的段類型」錯誤。Microsoft Graph與OneDrive API,邀請:失敗,不支持的段類型

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

看來v1.0版本目前沒有工作。我換到公測,使用此網址:

var endpointUrl = 'https://graph.microsoft.com/beta/me/drive/items/'+id+'/invite'; 

和它的作品

相關問題