Sharepoint webhooks:订阅列表
Sharepoint webhooks: Subscribing to a list
我正在尝试将应用程序订阅到 Sharepoint 列表。通知将通过 webhooks 发送到应用程序。为此,您必须向以下地址发出 HTTP POST 请求:
https://{your-account}.sharepoint.com/_api/web/lists('{list-guid}')/subscriptions
Body:
{
"resource": "{{ URL of the resource Id }}",
"notificationUrl" : "{{ URL of the endpoint that will process the webhooks }}",
"expirationDateTime" : "2017-09-27T00:00:00+00"
}
调用需要访问令牌。我是这样用curl获取token的:
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "client_id={{ Id of the application registered on Azure Active Directory }}&client_secret={{ Key added on Azure for the app }}&grant_type=client_credentials&resource=https%3A%2F%2F{{ My account }}.sharepoint.com" "https://login.microsoftonline.com/{{ Azure account tenant id}}/oauth2/token"
此 returns 作为 header 包含在 POST 请求中的令牌。不幸的是,此请求失败,错误代码为 401。Body:
{
"error_description" : "The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs."
}
我认为问题不是令牌,我们尝试了太多次才停止抛出与无效令牌数据相关的错误。
有没有办法调试这个错误?有什么建议么?
最后,问题是访问令牌,我们能够获得正确的访问令牌。有两种方法,这些方法适用于单租户应用程序。
方法一:两步不发送Azure凭据(仅app凭据)
第一步:申请验证码。
访问此 URL。它会将您重定向到查询字符串中传递的 redirect_uri,重定向的查询字符串将包含用于请求令牌的代码。
https://login.microsoftonline.com/{{ Tenant id }}/oauth2/authorize?client_id={{ Application id }}&response_type=code&redirect_uri={{ URI of the application }}&response_mode=query&resource={{ Resource that you want to access}}&state=12345
资源示例:https%3A%2F%2Fyouraccount.sharepoint.com
第 2 步:请求令牌
curl -X POST -H "content-type: application/x-www-form-urlencoded" -d "grant_type=authorization_code&client_id={{ Application code }}&code={{ The code received in the last request }}&redirect_uri={{ Same redirect URI }}&resource={{ Same resource}}&client_secret={{ Application key }}" https://login.microsoftonline.com/{{ Tenant id }}/oauth2/token
方法二:一步,发送Azure凭据
curl -i -X POST -d "grant_type=password&resource={{ Resource id }}&client_id={{ App id }}&username={{ Azure username }}&password={{ Azure password }}" "https://login.windows.net/{{ Tenant id }}/oauth2/token"
我正在尝试将应用程序订阅到 Sharepoint 列表。通知将通过 webhooks 发送到应用程序。为此,您必须向以下地址发出 HTTP POST 请求:
https://{your-account}.sharepoint.com/_api/web/lists('{list-guid}')/subscriptions
Body:
{
"resource": "{{ URL of the resource Id }}",
"notificationUrl" : "{{ URL of the endpoint that will process the webhooks }}",
"expirationDateTime" : "2017-09-27T00:00:00+00"
}
调用需要访问令牌。我是这样用curl获取token的:
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "client_id={{ Id of the application registered on Azure Active Directory }}&client_secret={{ Key added on Azure for the app }}&grant_type=client_credentials&resource=https%3A%2F%2F{{ My account }}.sharepoint.com" "https://login.microsoftonline.com/{{ Azure account tenant id}}/oauth2/token"
此 returns 作为 header 包含在 POST 请求中的令牌。不幸的是,此请求失败,错误代码为 401。Body:
{
"error_description" : "The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs."
}
我认为问题不是令牌,我们尝试了太多次才停止抛出与无效令牌数据相关的错误。
有没有办法调试这个错误?有什么建议么?
最后,问题是访问令牌,我们能够获得正确的访问令牌。有两种方法,这些方法适用于单租户应用程序。
方法一:两步不发送Azure凭据(仅app凭据)
第一步:申请验证码。 访问此 URL。它会将您重定向到查询字符串中传递的 redirect_uri,重定向的查询字符串将包含用于请求令牌的代码。
https://login.microsoftonline.com/{{ Tenant id }}/oauth2/authorize?client_id={{ Application id }}&response_type=code&redirect_uri={{ URI of the application }}&response_mode=query&resource={{ Resource that you want to access}}&state=12345
资源示例:https%3A%2F%2Fyouraccount.sharepoint.com
第 2 步:请求令牌
curl -X POST -H "content-type: application/x-www-form-urlencoded" -d "grant_type=authorization_code&client_id={{ Application code }}&code={{ The code received in the last request }}&redirect_uri={{ Same redirect URI }}&resource={{ Same resource}}&client_secret={{ Application key }}" https://login.microsoftonline.com/{{ Tenant id }}/oauth2/token
方法二:一步,发送Azure凭据
curl -i -X POST -d "grant_type=password&resource={{ Resource id }}&client_id={{ App id }}&username={{ Azure username }}&password={{ Azure password }}" "https://login.windows.net/{{ Tenant id }}/oauth2/token"