【发布时间】:2019-12-18 15:40:51
【问题描述】:
我需要在无需人工操作的情况下将文件(和元数据)按需上传到 Sharepoint 服务器。
我可以在 Sharepoint 之外使用 Sharepoint REST API 表单吗?我可以启动 NodeJS 服务器并从外部通过 PnPJS 访问吗?
【问题讨论】:
标签: javascript sharepoint
我需要在无需人工操作的情况下将文件(和元数据)按需上传到 Sharepoint 服务器。
我可以在 Sharepoint 之外使用 Sharepoint REST API 表单吗?我可以启动 NodeJS 服务器并从外部通过 PnPJS 访问吗?
【问题讨论】:
标签: javascript sharepoint
是的,我们可以从 SharePoint 外部(即外部网站)对 SharePoint 进行 REST API POST 调用。假设您的外部网站是 "AAA" 并将数据发送到 SharePoint 网站,即 "BBB" - 所以为了在 SharePoint 中进行身份验证,我们需要生成 client_id 和 client_secret 来自 SharePoint 网站 - 然后在编写对 SharePoint 的 POST 调用时,我们需要使用 client_id 和 client_secret 代码。
以下是如何从 SharePoint 生成“client_id”和“client_secret”的步骤:
为了实现这种访问 - 我们需要从“https://BBB.sharepoint.com”站点生成 client_id 和 client_secret,并在发送时在“AAA”站点中使用该代码数据“BBB”网站。
client_id和client_secret代码的生成步骤很长。
第 1 步:注册插件
转到您的 BBB 网站的此页面 https://.SharePoint.com/_layouts/15/appregnew.aspx
在这里你会得到:client id和client secret
将此信息保存在记事本中。
第 2 步:授予加载项权限
转到您 BBB 网站的此页面:
https://.sharepoint.com/_layouts/15/appinv.aspx
在 App ID 字段中输入“Client ID”并点击 Lookup 按钮
现在以 XML 格式输入以下权限请求:
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="Read" />
</AppPermissionRequests>
第 3 步:检索租户 ID
在 POST 人工工具中对此 URL(BBB 站点)执行 GET 请求:
https:///sharepoint.com/_vti_bin/client.svc/
从 Header 部分您将获得 realm 值,它只是您的客户端 ID。
最后,当您将 client id 和 client secret 发送到 AAA 站点(您从中上传文档),格式如下:
client_id ClientID@TenantID
client_secret ClientSecret
示例:
client_id: 4b4276d0-74cd-4476-b66f-e7e326e2cb93@10267809-adcb-42b6-b103-c7c8190b3fed
client_secret: nuC+ygmhpadH93TqJdte++C37SUchZVK4a5xT9XtVBU=
现在,当这里的其他系统是应用程序 “AAA 站点” 执行 POST 调用到“SharePoint 站点这里是 https://BBB.sharepoint.com”时,他们需要使用这两个 client_id 和 client_secret 密钥。
详细解释在这里:
https://www.ktskumar.com/2017/01/access-sharepoint-online-using-postman/
推荐:
从这里https://www.getpostman.com/downloads/下载POST man工具
使用此工具和上面的 client_id 和 client_secret 代码向 SharePoint 发出示例 POST 请求 - 然后生成 POST 请求 API 代码,无论哪种语言都适合您几乎所有的编程语言可以使用 POST man 工具 - 如果您使用 C# 工作 - 您可以获得 C# 等效代码用于 POST 调用 - 然后您可以在 Visual Studio 或您正在使用的任何工具中的实际应用程序中使用相同的代码。
【讨论】:
如果你想使用 Node JS 访问 SharePoint,我们可以使用 node-sp-auth 来通过身份验证。 node-sp-auth 允许您使用不同的身份验证技术对 nodejs 执行 SharePoint 无人值守(无需用户交互)http 身份验证。
更多信息在这里:
node-sp-auth - nodejs to SharePoint unattended http authentication
【讨论】: