【发布时间】:2021-05-11 03:17:38
【问题描述】:
我们正在通过 PnPjs 框架和使用 Sharepoint App Add-In 与 Sharepoint Online 的文档库进行交互(我们目前无法使用 Graph API)
我们的插件可以完全控制我们的网站:
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="FullControl" />
</AppPermissionRequests>
我们几乎可以执行我们想要的所有操作 - 创建/删除文件夹、添加文件、复制文件等。我们坚持的一件事是将已上传到 Sharepoint 的 .pptx 文件导出到 . pdf 文件,来自代码。
这是我如何从文档库列表中检索 .pdfConversionUrl 以制定对 Microsoft 媒体转换服务的请求:
let options: RenderListDataOptions = RenderListDataOptions.EnableMediaTAUrls | RenderListDataOptions.ContextInfo | RenderListDataOptions.ListData | RenderListDataOptions.ListSchema;
const viewXml: string = `
<View Scope='RecursiveAll'>
<Query>
<Where>
<In>
<FieldRef Name='ID' />
<Values>
<Value Type='Counter'>{{OUR SP DOCUMENTS LIST ID}}</Value>
</Values>
</In>
</Where>
</Query>
<RowLimit>1</RowLimit>
</View>`;
const listStream = await sp.web.lists.getById({{OUR SP DOCUMENTS LIST ID}}).renderListDataAsStream({ RenderOptions: options, ViewXml: viewXml });
/*
* response contains this property:
* '.pdfConversionUrl': '{.mediaBaseUrl}/transform/pdf?provider=spo&inputFormat={.fileType}&cs={.callerStack}&docid={.spItemUrl}&{.driveAccessToken}'
* mediaBaseUrl, callerStack and driveAccessToken values are also included
*/
const pdfTransformURL = `${listStream.ListSchema['.mediaBaseUrl']}/transform/pdf?provider=spo&inputFormat=pptx&cs=${listStream.ListSchema['.callerStack']}&docid={{LINK TO THE SP PPTX FILE}}&${listStream.ListSchema['.driveAccessToken']}`;
console.log(pdfTransformURL);
这是生成的 URL:
https://northcentralus1-mediap.svc.ms/transform/pdf?provider=spo&inputFormat=pptx&cs={{OUR SP CALLER STACK}}&docid={{LINK TO OUR SP PPTX FILE}}&access_token={{OUR ACCESS TOKEN}}
当我们向该 URL 发出 GET 请求时,响应将包含 PDF 文件的流,然后我们可以将其上传到 Sharepoint。 The process is outlined by the PnP team in this youtube video
但是,当我通过 node-fetch 或直接在浏览器中向该 URL 发出 GET 请求时,我收到以下错误消息:
{
"error":
{
"code":"generalException",
"message":"Exception: The remote server returned an error: (403) Forbidden. Access+denied.+Before+opening+files+in+this+location%2c+you+must+first+browse+to+the+web+site+and+select+the+option+to+login+automatically.",
"innererror":{"code":"Web_403Forbidden"}
}
}
我们搜索了它,发现我们需要在 SP 管理面板中启用选项以“允许不使用现代身份验证的应用程序”。我们这样做了,但我们仍然收到相同的错误消息。
如果有人之前尝试过此操作,请告诉我们如何解决此错误。谢谢!
【问题讨论】:
标签: sharepoint sharepoint-online pnp-js