我正在尝试从内容编辑器Web部件中名为List1的SharePoint列表中提取列表数据。我过去能够做到这一点没有任何问题,但由于某种原因,我现在尝试这样做只会出现401错误。当我将get请求的Url粘贴到浏览器中时,它会按预期提取数据。为什么SharePoint Online会阻止我的浏览器提取相同的数据?我也用ajax调用测试了这个并得到了相同的结果。
控制台出错:
HTTP401: DENIED - The requested resource requires user authentication.
GET - https://portal.office.com/SuiteServiceProxy.aspx?upn=MSoporito%40MichaelSoporito.com&suiteServiceReturnUrl=https%3A%2F%2Fmsoap.sharepoint.com%2FSitePages%2Ftest.aspx&returnUrl=https%3A%2F%2Fmsoap.sharepoint.com%2FSitePages%2Ftest.aspx&Silent=1
代码:
(function(angualr){
var appVar = angular.module('listApp', []);
appVar.controller("controller1", function($scope, $http){
var secondUrl = "https://msoap.sharepoint.com/_api/Web/Lists(guid'42540d2d-df19-477f-a57b-837d9de15641')/Items?$select=Title"
$http({
url: secondUrl,
method: "GET",
headers: {
"accept": "application/json;odata=verbose",
"content-Type": "application/json;odata=verbose"
},
success: function(data){
$scope.items = data.d.results;
},
error: function(sender,args){
console.log(args);
}
});
});
})(window.angular);
的Http:
<div ng-app="listApp">
<div id="App1" ng-controller="controller1">
<h1>First List Items</h1>
<div ng-repeat="item in items">
<p>{{item.Title}}</p>
</div>
</div>
</div>
<script src="https://msoap.sharepoint.com/SiteAssets/jquery-3.1.0.min.js"></script>
<script src="https://msoap.sharepoint.com/SiteAssets/angular.min.js"></script>
<script src="https://msoap.sharepoint.com/SiteAssets/script.js"></script>
答案 0 :(得分:0)
您可能在这里面临同样的问题: https://sharepoint.stackexchange.com/questions/115015/sharepoint-search-rest-api-401-unauthorized-error-need-help
在SharePoint Online中,您必须传递某些凭据才能完成身份验证。