2017-02-20 66 views
0

我正在使用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的訂閱,我找不到這個在線的任何資源。

+0

您是否搜索了關於駱駝腸衣的錯誤? – halfer

+0

是的,但問題應該與請求體有關,但同樣的請求在圖形瀏覽器中工作正常。 – Surbhi

回答

0

問題是由於它在默認情況下和訂閱API設置"@odata.type":"microsoft.graph.subscription"微軟圖形SDK的BaseSubscription模型沒有在請求體支持這一點,並引發錯誤:400

所以我通過明確使解決它"@odata.type"null在訂閱模型中,並將其傳遞給我成功運作的發佈請求。

謝謝!