繁体   English   中英

使用 Sharepoint REST API 和 Javascript 从 Sharepoint 外部上传文件?

[英]Upload files with Sharepoint REST API and Javascript from outside of Sharepoint?

我需要按需将文件(和元数据)上传到 Sharepoint 服务器,无需人工操作。

我可以在 Sharepoint 之外使用 Sharepoint REST API 表单吗? 我可以启动 NodeJS 服务器并从外部通过 PnPJS 访问吗?

是的,我们可以从 SharePoint 外部(即外部网站)对 SharePoint 进行 REST API POST 调用。 假设您的外部网站是“AAA”并将数据发送到 SharePoint 站点,即“BBB” - 因此为了在 SharePoint 中进行身份验证,我们需要从 SharePoint 站点生成client_idclient_secret - 然后在将 POST 调用写入 SharePoint 时,我们需要使用client_idclient_secret代码。

以下是如何从 SharePoint 生成“client_id”和“client_secret”的步骤:

为了实现这种访问 - 我们需要从“ https://BBB.sharepoint.com ”站点生成client_idclient_secret ,并在发送数据“BBB”站点时在“AAA”站点中使用该代码。

如何生成client_idclient_secret代码有很长的步骤。

第 1 步:注册加载项

转到您 BBB 网站的此页面 https://.SharePoint.com/_layouts/15/appregnew.aspx

在这里您将获得:客户端 ID客户端密码

将此信息保存在记事本中。

步骤 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 man 工具中对该 URL(BBB 站点)执行 GET 请求:

https:///sharepoint.com/_vti_bin/client.svc/

从 Header 部分,您将获得领域值,它只是您的客户端 ID。

所以最后,当您将客户端 ID客户端密码发送到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 站点”执行对“SharePoint 站点这里是https://BBB.sharepoint.com ”的POST调用时,他们需要使用这两个client_idclient_secret密钥。

详细解释在这里:

https://www.ktskumar.com/2017/01/access-sharepoint-online-using-postman/

推荐:

从这里下载 POST man 工具https://www.getpostman.com/downloads/

使用此工具和上述client_idclient_secret代码对 SharePoint 执行示例 POST 请求 - 然后生成适合您的 POST 请求 API 代码几乎所有编程语言都可以使用 POST man 工具使用 - 如果您使用 C# - 您可以获取 POST 调用的 C# 等效代码 - 然后您可以在 Visual Studio 或您正在使用的任何工具中的实际应用程序中使用相同的代码段。

如果要使用Node JS访问SharePoint,我们可以使用node-sp-auth来通过认证。 node-sp-auth 允许您使用不同的身份验证技术通过 nodejs 执行 SharePoint 无人值守(无需用户交互)http 身份验证。

更多信息在这里:

node-sp-auth - nodejs 到 SharePoint 无人值守 http 身份验证

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM