简体   繁体   English

SharePoint REST API

[英]SharePoint REST API

I need your help.我需要你的帮助。 I want to build a form on website x which send data to a Sharepoint to domain y.我想在网站 x 上构建一个表单,将数据发送到域 y 的 Sharepoint。 I have the Office 365 Enterprise - Business Essentials License我拥有 Office 365 Enterprise - Business Essentials 许可证

  1. Is that even possible?这甚至可能吗?
  2. What an where do I have to setup Office365 (API etc.)我必须在哪里设置 Office365(API 等)
  3. Hot to connect via SharePoint REST API?想要通过 SharePoint REST API 进行连接?

Can you guys give me an example for my HTML code.你们能给我举个 HTML 代码的例子吗? I have the same forms also in Sharepoint:我在 Sharepoint 中也有相同的表格:

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

    <title>Test</title>
  </head>
  <body>
    <h1>Test</h1>

        <!-- HTML Form (wrapped in a .bootstrap-iso div) -->
        <div class="bootstrap-iso">
         <div class="container-fluid">
          <div class="row">
           <div class="col-md-6 col-sm-6 col-xs-12">
            <form method="post">
             <div class="form-group ">
              <label class="control-label " for="name">
               Name
              </label>
              <input readonly class="form-control" id="name" name="name" value="" type="text"/>
             </div>
             <div class="form-group ">
              <label class="control-label " for="date">
               Date
              </label>
              <input readonly class="form-control" id="date" name="date" value="" type="text"/>
             </div>
            <div class="form-group ">
              <label class="control-label " for="time">
               Time
              </label>
              <input readonly class="form-control" id="time" name="time" value="" type="text"/>
             </div>
             <div class="form-group ">
              <label class="control-label " for="location">
               Location
              </label>
              <input readonly class="form-control" id="location" name="location" value="" type="text"/>
             </div>
             <div class="form-group">
              <div>
               <button class="btn btn-primary " name="submit" type="submit">
                Submit
               </button>
              </div>
             </div>
            </form>
           </div>
          </div>
         </div>
        </div>




    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
  </body>
</html>

Apart from CORS issue that Jeff mentioned in the comment, you need an App Registration in your SP Online environment: https://yourtenantname.sharepoint.com/_layouts/15/appregnew.aspx除了杰夫在评论中提到的 CORS 问题外,您还需要在 SP 在线环境中进行应用注册: https : //yourtenantname.sharepoint.com/_layouts/15/appregnew.aspx 在此处输入图片说明

and then assigning App permisssions at: https://yourtenantname.sharepoint.com/_layouts/15/appinv.aspx然后在以下位置分配应用程序权限: https ://yourtenantname.sharepoint.com/_layouts/15/appinv.aspx 在此处输入图片说明

Permissions XML:权限 XML:

<AppPermissionRequests AllowAppOnlyPolicy="true">
       <AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" 
        Right="FullControl"/>
    </AppPermissionRequests>

and then trusting the app.然后信任该应用程序。 These steps will provide you with an client id and secret that you need to use to implement OAuth 2.0 (authorization code grant flow or implicit grant flow depending upon your web app), which will get you the access token that you can use to authenticate SharePoint Rest API calls through authorization header.这些步骤将为您提供实现 OAuth 2.0 所需的客户端 ID 和密码(授权代码授权流程或隐式授权流程,具体取决于您的 Web 应用程序),这将为您提供可用于对 SharePoint 进行身份验证的访问令牌通过授权标头 Rest API 调用。

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

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