0

我正在尝试从内容编辑器 Web 部件中名为 List1 的 SharePoint 列表中提取列表数据。过去我可以毫无问题地执行此操作,但由于某种原因,我现在尝试执行此操作时只会收到 401 错误。当我将获取请求的 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); 

网址:

<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>
4

1 回答 1

0

您可能在这里遇到同样的问题: https ://sharepoint.stackexchange.com/questions/115015/sharepoint-search-rest-api-401-unauthorized-error-need-help

在 SharePoint Online 中,您必须传递某些凭据才能通过身份验证。

于 2017-03-20T01:47:58.200 回答