gpt4 book ai didi

javascript - 使用 REST API 在 SharePoint Online 中外部共享文件夹

转载 作者:太空宇宙 更新时间:2023-11-04 16:26:08 27 4
gpt4 key购买 nike

我是 SharePoint Online 和 REST API 的新手。

我目前正在开发一个 SharePoint 加载项,它可以在驻留在主机 Web 中的文档库中创建文件夹,并向指定的外部用户共享权限。我目前正在尝试使用 REST API 完成所有操作。

我已成功创建文件夹,但目前无法将文件夹共享给外部用户

我在尝试使用主机 Web 上下文时解析以下端点时遇到问题。下面的第一个端点用于解析外部电子邮件,第二个端点用于向外部用户执行文件夹的实际共享。

[appUrl]/_api/SP.AppContextSite(@target)/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerResolveUser?@target='[hostUrl]'

[appUrl]/_api/SP.AppContextSite(@target)/SP.Web.ShareObject?@target='[hostUrl]'

我收到错误 404 Not Found:无法找到请求 SP.UI.ApplicationPages.ClientPeoplerPickerWebServiceInterface.clientPeoplePickerResoveUser 的资源。当我尝试强制运行 SP.Web.ShareObject 时,也会发生同样的错误。

下面是我正在使用的 JavaScript

var ShareToRecipients = function(folder, recipient, appUrl, hostUrl){

var url = appUrl = "/_api/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerResolveUser";
url = WebComponents().getTargetUrl(url, hostUrl);

var sharedDocUrl = hostUrl + "/ExternalShareDocLib/" + foldername;

var checkUser = $.ajax({
url: url,
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify({
'queryParams': {
"__metadata": {'type': "SP.UI.ApplicationPages.ClientPeoplePickerQueryParameters"},
"AllowEmailAddresses": true,
"AllowMultipleEntities": false,
"AllUrlZones": false,
"MaximumEntitySuggestions": 50,
"PrincipalSource": 15,
"PrincipalType": 1,
"QueryString": recipient
}
}),
headers:{
"accept": "application/json;odata=verbose",
"X-RequestDigest": $('#__REQUESTDIGEST').val()
},

error: function(jqXHR, textStatus){
myapp.LogAPIError(jqXHR, textStatus)
}
});

checkUser.success(function(data){
var user = data.d.ClientPeoplePickerResolveUser;
var result = JSON.parse(users);

if(users !== undefined){
var reqUrl = appUrl + "/_api/SP.Web.ShareObject";
reqUrl = WebComponents().getTargetUrl(reqUrl, hostUrl);

var shareCall = $.ajax({
url: reqUrl,
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify({
"url": reqUrl,
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify({
"url": sharedDocUrl,
"peoplePickerInput": '[' + user + ']',
"roleValue": "1073741827",
"groupId": 0,
"propagateAcl": false,
"sendEmail": true,
"includeAnonymousLinkInEmail": true,
"emailSubject": "A document folder has been shared to you",
"emailBody": "A document folder has been shared to you. The folder name is " + folder
})
});
});

shareCall.success(function(data){
myApp.LogInformation("Successfully shared " + folder + " to " + recipient);
});

shareCall.error(function(jqXHR, textStatus){
myApp.LogAPIError(jqXHR, textStatus);
});
}
});}

用于生成主机 URL 端点

var WebComponents = function(){
var getTargeturl = function (url, hostUrl){
if(hostUrl){
var api = "_api/";

var index = url.indexOf(api);
url = url.slice(0, index + api.length)+
"SP.AppContextSite(@target)" +
url.slice(index + api.length);

var connector = "?";
if(url.indexOf("?") > -1 && url.indexOf("$") > -1){
connector = "&";
}

url = url + connector + "@target='" + hostUrl + "'";
}

return url;
}

return{
getTargeturl: getTargeturl
}}

您能否帮助验证我是否正确使用端点以及我尝试做的事情是否可行?感谢您的帮助。

干杯,尼尔

最佳答案

添加我的解决方案,以防其他人遇到此问题。我能够通过以下方式使用 API:

  1. 删除url = WebComponents().getTargetUrl(url, hostUrl)和reqUrl = WebComponents().getTargetUrl(reqUrl, hostUrl)。
  2. 通过 AppManifest.xml租户中的应用提供完全控制

关于javascript - 使用 REST API 在 SharePoint Online 中外部共享文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40200178/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com