I am implementing events subscription using MS graph android SDK. Below is the code.
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;
}
The request body generated through this always throws the error:
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]
but the same request body is working fine in graph explorer,
I have tried many things now but unable to resolve it. How can I get this to work for subscriptions in Android, I can't find any resources for this online.
The issue was due to the BaseSubscription model in Microsoft graph SDK where it is setting "#odata.type":"microsoft.graph.subscription" by default and subscription api is not supporting this in request body and throwing the error: 400
So I resolved it by explicitly making "#odata.type" to null in the subscription model and pass it to post request which worked successfully for me.
Thanks!
Related
I am facing problem implementing the POST RETROFIT in openrouteservices maps to get round route.
Attached photo below is the error log.Enter image description here
This is my API Interface
Call<Round> getRoundCoordinates(
/*#Header("Content-Type: application/json") String authHeader ,*/
#Header("Authorization") String authHeader,
#Query("coordinates") List<List<Double>> coordinates,
#Query("length") int length,
#Query("seed") int seed
);
and 500 Error code is showing. Anyone who can help .Thanks in Advance :)
Error 500 is a server internal error. So either it cannot handle your parameter values or it is totally independent from client-side, the error lays in server code.
From the official document -
The 500 (Internal Server Error) status code indicates that the server
encountered an unexpected condition that prevented it from fulfilling
the request.
So you need to discuss with you backend team about it because it is an error occurred in the server, not your app (Client-side)
This is how my request looks like:
ApiService apiService = retrofit.create(ApiService.class);
Observable<Response<UserUpdateResponse>> response = apiService.updateUser(Utils.getHeader(), object);
response.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::onSuccessUpdate,
this::onErr,
this::hideDialogLoading);
It's supposed to return 'code':'205' 'msg':'successfully update'. But when server response any code 201,202 (anything not 200) it will go to error.
Here is the Error.
java.net.ProtocolException: HTTP 205 had non-zero Content-Length: 121
So how do I prevent it from error, or how do I get error body? Thank you!.
HTTP response codes have a predefined definition and some have requirements that they must fullfill to be considered a valid HTTP payload. You cannot redefine what these codes mean for your application and expect well-implemented clients to accept it.
Looking specifically at HTTP 205 - Reset Content, which has the following requirement:
Since the 205 status code implies that no additional content will be provided, a server MUST NOT generate a payload in a 205 response.
Generally applications will just return HTTP 200 for all requests and include application-specific error codes in the payload. What you're doing does not make much sense.
So technically, I can get response 2xx. The problem was that server response body in response code 205 that suppose to be null (https://www.rfc-editor.org/rfc/rfc7231#section-6.3.6). So after set body null on server, android side works fine.
Following the instructions on UrbanAirship documentation, I need to add a TagGroup to a namedUser with this lines of code on a demo App in Android
airship.getPushManager().getNamedUser().setId("123456");
airship.getPushManager().getNamedUser().editTagGroups().addTag("loyalty", "elite").apply();
But, the LogCat shows this error:
D/UrbanAirshipDemo - UALib﹕ Received a response for tag groups: Response: ResponseBody: ResponseHeaders: {null=[HTTP/1.1 400 Bad Request], Connection=[close, Transfer-Encoding], Content-Type=[application/vnd.urbanairship+json; version=3], Date=[Wed, 24 Jun 2015 20:02:06 GMT], Transfer-Encoding=[chunked], X-Android-Received-Millis=[1435176126629], X-Android-Response-Source=[NETWORK 400], X-Android-Sent-Millis=[1435176126427]} ResponseMessage: Bad Request Status: 400
E/UrbanAirshipDemo - UALib﹕ Update tag groups failed with status: 400
E/UrbanAirshipDemo - UALib﹕ Both add & remove fields are present and the intersection of the tags in these fields is not empty.
Is it something weird on their API? Instructions from here: http://docs.urbanairship.com/platform/android.html#named-user-tag-groups
Is just simple the implementation, but their API is returning 400. Push notifications are working fine
I was able to reproduce the same issue. The error message is incorrect, the real issue is the tag group does not exists yet. Groups can only be created through Go. Try creating the group following - http://docs.urbanairship.com/topic-guides/tag-groups-walkthrough.html#create-a-tag-group and try again.
The error message will be fixed in a future release.
I am trying to get authenticated token from GoogleAuthUtils. Keep having Invalid Client ID message like this.
GLS error: INVALID_CLIENT_ID myEmailAddress audience:server:client_id:NUM.apps.googleusercontent.com:api_scope:https://picasaweb.google.com/data
The NUM = xxxxxxx-yyyyyyyy.apps.googleusercontent.com where I used xxxxxxx part. I even tried using the y parts or both but none works. Am I missing something here?
String token = GoogleAuthUtil.getToken(PicassaFragment.this.getActivity(),
Plus.AccountApi.getAccountName(client),
scope
);
This is the code i received the error message.
I found how to send push notification to Android device using Django here (here is the code).
So adopted that and my code looks like this:
def sendAndroidPushNotification(registration_id, collapse_key, a, b) :
try:
auth = getNewAndroidAuthorizationToken() # this works I'm fetching new token so this is up to date (its length is 267 characters)
push_request = urllib2.Request("https://android.apis.google.com/c2dm/send")
data = urllib.urlencode({'data.testA' : a,
'data.testB' : b,
'collapse_key' : collapse_key,
'registration_id': registration_id
})
push_request.add_data( data )
push_request.add_header('Authorization', 'GoogleLogin auth=' + auth)
push_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
push_request.add_header('Content-Length', len(data))
urllib2.build_opener().open(push_request)
except urllib2.HTTPError as e:
print 'got exception during push notification'
print 'Reason: "{0}" code: {1}'.format(e.reason, e.code)
pass
this give me error: "Reason: "Unauthorized" code: 401" (at some point it was 403). Version which uses httplib.HTTPSConnection instead of urllib2.Request has same problem.
It looks almost the same as code shown here so I'm totally confused. What I'm doing wrong?
Edit:
Just in case, here is how I fetch authorization token (it looks like that it works fine), maybe my parsing is wrong:
def getNewAndroidAuthorizationToken() :
request = urllib2.Request("https://www.google.com/accounts/ClientLogin")
data = urllib.urlencode({'accountType' : 'HOSTED_OR_GOOGLE',
'Email' : 'someaccount#gmail.com',
'Passwd' : 'asdjsdfa',
'service' : 'ac2dm',
'source' : 'com.mycompany.mypackage',})
request.add_data(data)
content = urllib2.build_opener().open(request)
lines = content.readlines()
for line in lines :
if line.find("Auth=")==0 :
return line[5:]
return
C2DM is deprecated. Developers are encouraged to switch to GCM, C2DM will be supported for a short time. Simple API instead of ClientLogin and oAuth2 which are not supported.
http://developer.android.com/guide/google/gcm/index.html