Getting JSON Exception While connecting GCM through curl - android

I am getting an error when I make a curl request to GCM server:
JSON_PARSING_ERROR: Unexpected character (m) at position 0
curl request:
curl -i -H "Content-Type: application/json" -H "Authorization: key=AIzaSyAuKLBnVEv_bm4fp88RqKaVm8DClzc"
-X POST -d "message":"Hi I am Developer","registration_ids":"["APA91bGj-wkz4m6tEaFfual2HuRHNAn3CmAE6nRmv5LaOnuWa_6D3AnacqTmSCHXiKvdzINVc_XUGJhrXk0z5hQomdCM_9Nf6QqB-Pf9Q6Tf_DraUZZaUVtDiaRaIStgXsx0zMFqKJHU0q75OGCtq5OSGR11l3mCB5DBtzvl4nFwOws_UuA"]"
https://android.googleapis.com/gcm/send

I don't know anything about GCM API, but I see the error. You don't send the valid JSON string and server can't parse it.
Wrap your data in curly braces. Replace
-d "message":"Hi I am Developer","registration_ids":"["APA91bGj-wkz4m6tEaFfual2HuRHNAn3CmAE6nRmv5LaOnuWa_6D3AnacqTmSCHXiKvdzINVc_XUGJhrXk0z5hQomdCM_9Nf6QqB-Pf9Q6Tf_DraUZZaUVtDiaRaIStgXsx0zMFqKJHU0q75OGCtq5OSGR11l3mCB5DBtzvl4nFwOws_UuA"]"
with
-d '{"message":"Hi I am Developer","registration_ids":"["APA91bGj-wkz4m6tEaFfual2HuRHNAn3CmAE6nRmv5LaOnuWa_6D3AnacqTmSCHXiKvdzINVc_XUGJhrXk0z5hQomdCM_9Nf6QqB-Pf9Q6Tf_DraUZZaUVtDiaRaIStgXsx0zMFqKJHU0q75OGCtq5OSGR11l3mCB5DBtzvl4nFwOws_UuA"]"}'

Related

How to send logcat by curl POST command

Need to send by shellscript every new string in Android logcat by curl POST command to server. Connected to Android by ADB.
I was trying this things:
#logcat com.mm.en:I -e "chat"| tee /sdcard/Pictures/out.txt
It makes a file, and write every new string to it.
Next i was trying:
#curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST http://nnnn.ru/test/testprint.php -G -d '{"id":"IDVALUE","name":"Mike"}'
It is also work.
But when i trying to combine it by guide, it doesnt work:
#logcat com.mm.en:I -e "chat"| curl -H 'Content-Type: application/json' http://nnnn.ru/test/testprint.php -d #-
Where i`m wrong?

Android - Curl command to Volley Request

I have curl request to push data to the server from Android.Below is the Curl request:
curl -v -H "Accept: application/json" -H "Content-type: application/json" -H "Authorization: Token token=SNKh9UP4RX2Ltyxo9JnG , username=local1admin" -X PATCH -d '{"fcm": {"token":"sd7sdf6sdffd5"}}' http://myapp-back.herokuapp.com/fcms/1
How should I do post request using volley? I am confused because I have no idea where to put this:
'{"fcm": {"token":"sd7sdf6sdffd5"}}'
So please anyone help me to get it done. Any answers are appreciable. Thank you.
Peace out!
I ran into similar issue with my curl command below -
curl 'https://ws.test.com/handle_email?embed_load_code=undefined' -H 'Accept: /' -H 'Referer: https://cdn1.test.com/widgets/12345/12345/widget.html' -H 'Origin: https://cdn1.test.com' -H 'User-Agent: Test App' -H 'DNT: 1' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data 'campaign=12345&merchant=12345&original_data=%257B%2522site%2522%253A%2522site-11111-www.test.com%2522%257D&share_id=&email=test%40test.com' —compressed
Easy way to figure out how to organize the different pieces of cUrl query to Volley Request is by first running this cUrl query in Post Man and intercept request object in Charles Proxy - Ref : Simulate a specific CURL in PostMan
In my case -
-H values were added as Header items
--data values are added as body
Content-Type set as application/x-www-form-urlencoded

parse getInBackground throws InvalidKeyName exception

I am trying to migrate my Parse app to MongoDB. I have got MangoDB up up and running and connected to pars.com server as described in parse.com/docs/server/guide#migrating.
Now I am trying to connect to my Parse server from Android Parse SDK version is 1.13.0.
Initialization is:
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId("apid")
.clientKey("key")
.server("http ://server:1337")
.enableLocalDataStore()
.build());
GET method works fine from command line:
curl -X GET -H "X-Parse-Application-Id: " -H "X-Parse-Master-Key: " -G http : //serverip:1337/classes/New/EXOIesqEa3 {"objectId":"EXOIesqEa3","Name":"Third","createdAt":"2016-01-31T14:24:18.950Z","
However, it dose not work in Android SDK, as it uses POST instead of GET with body, something like:
curl -X POST -H "key" -H "Content-Type: application/json" -d '{"where":"{\"objectId\":\"iXMRHnQN1a\"}","_method":"GET"}' http://server:1337/classes/GameScore1
Parse server response is InvalidKeyName exception: {"code":105,"error":"invalid key name: 0"}.
Can someone help here to figure out why it returns this InvalidKeyName exception?
Please note that:
curl -X POST -H "X-Parse-Application-key" -H "Content-Type: application/json" -d '{"_method":"GET"}' http://server:1337/classes/GameScore1
works fine.

Apache Cordova Android Push Notification Aerogear Unable To Send

While using
curl -3 -u \
"f07c43a6-bb0a-4bb7-a1eb-a368db272212:e2cf19c3-6636-4712-bbe8-26b7c1ac9c09" \
-v -H "Accept: application/json" -H "Content-type: application/json" \
-X POST -d '{"message": {"alert":"Hello AeroGear", "badge":1}}' \
https://aerogear-html5.rhcloud.com/rest/sender
to push notification
I am getting 401 unauthorised request.Unable to figure out how to authenticate?
Make sure your authorization parameters(through -u) are valid and also make sure you are using the correct credential for the service you are trying to access.
Also, if you are from windows(for linux its ok) then wrap the post parameters with double quotes(") Instead of single(').
-d "{\"message\": {\"alert\":\"Hello AeroGear\", \"badge\":1}}"
Going to this link https://aerogear-html5.rhcloud.com, produces a website not available
Is there a specific tutorial you used to get that curl command?

Sending a message to C2DM keeps returning 401

I have been trying this for two days already with no success. My goal is to send a short message to the C2DM. I have used a simple Java application and curl, but it keeps returning response code 401: (Unauthorized).
The first curl command:
curl https://www.google.com/accounts/ClientLogin -d Email=firstname.lastname#gmail.com -d Passwd=mypasswd -d accountType=HOSTED_OR_GOOGLE -d source=Google-cURL-Example -d service=ac2dm
returns three long strings: SID, LSID and Auth.
Next, I copy the Auth string to the following command (AUTH_STRING):
curl --header "Authorization: GoogleLogin auth=AUTH_STRING" "https://android.clients.google.com/c2dm/send" -d registration_id=SOME_REGISTRATION_ID -d "data.message=HelloWorld" -d collapse_key=0 -k
but it always returns response code 401. The registration_id is copied from the Android client app and it should be valid.
What's wrong with this? Any help is appreciated.
Problem solved by using the correct email address and password in the first curl command. Email credentials that were used when signing for ac2dm should be used.

Categories

Resources