ホストサイトのApp Webからリストにアクセスすると、アクセスが拒否されました
-
10-12-2019 - |
質問
CSOM(JavaScript)を使用して、SharePointホストアプリからホストサイトにあるリストのタイトルを取得しようとしています。マニフェストファイルにアクセス許可を追加し、リストを選択しましたが、それでもexecuteQueryAsyncでアクセスが拒否されました。これが私のコードです:
hostweburl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
var hostcontext = new SP.ClientContext(hostweburl);
var oList = hostcontext.get_web().get_lists().getByTitle('SliderList');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(' som query to get proper items')
this.collListItem = oList.getItems(camlQuery);
hostcontext.load(collListItem);
hostcontext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
.
OnQuerySuccessまたはonQueryFailedには行かない、それはSP_ClientRuntimeContext $ executeQueryAsync、sp.runtime.debug.js、行3103 で拒否されました。
解決
ホストWebには、 App Web と sp.appcontextSite のSP.ClientContextを生成する必要があります。ホストWebのリストへの参照を取得するには、次のことを試してください。
.// Get the ClientContext for the app web
clientContext = new SP.ClientContext.get_current();
// Use the host web URL to get a parent context - this allows us to get data from the parent
hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
parentCtx = new SP.AppContextSite(clientContext, hostweburl);
parentWeb = parentCtx.get_web();
parentList = parentWeb.get_lists().getByTitle("SliderList");