Android 401 for c2dm
I got registration_id
and authoCode
using same gmail id but still I'm getting "Unauthorized". I am clueless now what can be wrong.
While Sign Up for Android Cloud to Device Messaging. If I'm using abc@gmail.com, I am using same abc@gmail.com in
Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));
registrationIntent.putExtra("sender", "abc@gmail.com");
this.startService(registrationIntent);
same for the while getting authCode
https://www.google.com/accounts/ClientLogin?accountType=GOOGLE&Email=abc@gmail.com&Passwd=XXXXX&source=XXXXXXX-0.1&service=cl
Code I am using is
$headers = array('Authorization: GoogleLogin auth=' . $authCode);
$data = array(
'registration_id' => $registrationId,
'collapse_key' => "test",
'data.m开发者_运维百科essage' => "wass up" //TODO Add more params with just simple data instead
);
print_r($headers);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://android.apis.google.com/c2dm/send");
if ($headers)
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
curl_close($ch);
echo($response);
return $response;
These are the steps I followed
- I created a new google account for my app
- Registered it with http://code.google.com/android/c2dm/signup.html
- First ran the app on the simulator to get the registration id
- Used the same gmail id to get the authCode
- After getting authCode and RegistartionId, I am trying to send the message.
Am I missing any steps?
Ok this was bad on my side.
The code is good but i was asking auth code for wrong service
for all those ppl like me who just copy/paste example
for c2dm
https://www.google.com/accounts/ClientLogin?accountType=GOOGLE&Email=XXXXX&Passwd=XXXXX&source=Google&service=ac2dm
In google doc they have given example for google calendar service=cl
hope this help anyone
精彩评论