通过webhooks使用MS图Android SDK的事件订阅
问题描述:
我正在使用MS图android SDK实现事件订阅。以下是代码。通过webhooks使用MS图Android SDK的事件订阅
IGraphServiceClient mGraphServiceClient = GraphServiceClientManager.getInstance(context).getGraphServiceClient();
mGraphServiceClient.getSubscriptions().buildRequest().post(getSubscription(email, expirationDate), subscriptionICallback);
private Subscription getSubscription(String email, Calendar expirationDate) {
Subscription subscription = new Subscription();
subscription.expirationDateTime = expirationDate;
subscription.notificationUrl = "<Webhook link>";
subscription.changeType = "created,updated";
subscription.resource = "me/events";
subscription.clientState = Base64.encodeToString(email.getBytes(), Base64.URL_SAFE | Base64.NO_PADDING | Base64.NO_WRAP);
return subscription;
}
通过该产生的请求主体总是抛出的错误:
Error during http request Error code: InvalidRequest
Error message: Could not process subscription creation payload. Are all property names spelled and camelCased properly?
POST https://graph.microsoft.com/v1.0/subscriptions
SdkVersion : graph-android-v1.0.0
Authorization : Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI[...]
{"@odata.context":"https://graph.microsoft.com/v1.[...]
400 : Bad Request
E/DefaultHttpProvider[sendRequestInternal] - 286: [...]
E/DefaultHttpProvider[sendRequestInternal] - 286: [Some information was truncated for brevity, enable debug logging for more details]
E/DefaultHttpProvider[sendRequestInternal] - 286: Throwable detail:
com.microsoft.graph.http.GraphServiceException: Error code: InvalidRequest
Error message: Could not process subscription creation payload. Are all property names spelled and camelCased properly?
POST https://graph.microsoft.com/v1.0/subscriptions
SdkVersion : graph-android-v1.0.0
Authorization : Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI[...]
{"@odata.context":"https://graph.microsoft.com/v1.[...]
400 : Bad Request
[...]
[Some information was truncated for brevity, enable debug logging for more details]
at com.microsoft.graph.http.DefaultHttpProvider.handleErrorResponse(DefaultHttpProvider.java:310)
at com.microsoft.graph.http.DefaultHttpProvider.sendRequestInternal(DefaultHttpProvider.java:246)
at com.microsoft.graph.http.DefaultHttpProvider.access$000(DefaultHttpProvider.java:47)
at com.microsoft.graph.http.DefaultHttpProvider$1.run(DefaultHttpProvider.java:129)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
E/agenday.com.pgi.agenday.ui.BaseActivity: create Subscription exceptionError code: InvalidRequest
Error message: Could not process subscription creation payload. Are all property names spelled and camelCased properly?
POST https://graph.microsoft.com/v1.0/subscriptions
SdkVersion : graph-android-v1.0.0
Authorization : Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI[...]
{"@odata.context":"https://graph.microsoft.com/v1.[...]
400 : Bad Request
[...]
[Some information was truncated for brevity, enable debug logging for more details]
但同样的请求体在图探险家做工精细, 我已经尝试了很多东西,现在却无力解决。我怎样才能让这个工作在Android的订阅,我找不到这个在线的任何资源。
答
问题是由于它在默认情况下和订阅API设置"@odata.type":"microsoft.graph.subscription"
微软图形SDK的BaseSubscription模型没有在请求体支持这一点,并引发错误:400
所以我通过明确使解决它"@odata.type"
到null
在订阅模型中,并将其传递给我成功运作的发布请求。
谢谢!
您是否搜索了关于骆驼肠衣的错误? – halfer
是的,但问题应该与请求体有关,但同样的请求在图形浏览器中工作正常。 – Surbhi