c2dm Invalid registration problem

72 views
Skip to first unread message

Talal Fathy

unread,
Sep 13, 2011, 3:53:10 AM9/13/11
to android-c2dm
Dears,

I am using the below PHP code to authenticate and send push
notification message but i always get an error of
"InvalidRegistration"

Could any one helps me where is the error

Here is the php code

<?php
$registrationId =
"APA91bHq2nStGpUCIUm5MHinUjazU59daAYvdCz8tUheysiWgo_Skjs8mmnQ-
jtZA5HKHHedjLiDD_JH5LkdjqbepU9FtOlAVQXH93fvv9boM8qvhcZQq-E";
$email = "tala...@gmail.com";
$password = "XXXX";

// get auth code
$headers = array('Content-Type: application/x-www-form-urlencoded');
$postFields = "Passwd=".
$password."&accountType=HOSTED_OR_GOOGLE&source=talalilo-
xms-1.0.0&service=ac2dm&Email=".$email;
if(!$curl = curl_init()){
die('curl not found');
}

curl_setopt($curl, CURLOPT_URL, "https://www.google.com/accounts/
ClientLogin");
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_HEADER, TRUE);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, TRUE);
$response = curl_exec ($curl);
curl_close ($curl);

// send message
$split = explode('Auth=', $response);
$Auth = $split[1];
$postFields = "registration_id=".
$registrationId."&data.message=MessageSentFromServer&collapse_key=storedmessages";

$authCode=$Auth;
$msgType = '1';
$messageText = 'talal';
$postFields = "registration_id=".
$registrationId."&data.message=MessageSentFromServer&collapse_key=storedmessages";

$data = array(
'registration_id' => $registrationId,
'collapse_key' => 'ck_' . $msgType,
'data.payload' => $messageText
);

$headers = array("registration_id:
APA91bEYl5wxxvINCKUbVa6lTXoCtYx1sVT0M2tj4Q6nKNIVbUOZI0XBfU70uBXow-
wrCYkwjK6CQ6qOXtEWpvCKXh6Ux2-k60bAyaHCTnRcmqrsNr_4FUU", "Content-Type:
application/x-www-form-urlencoded", "Content-Length: ".strlen($data),
'Authorization: GoogleLogin auth='.$authCode);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://android.apis.google.com/c2dm/
send");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, TRUE);

$response2 = curl_exec($ch);
curl_close($ch);
echo $response2;
?>

Mike Willbanks

unread,
Sep 22, 2011, 10:18:04 PM9/22/11
to androi...@googlegroups.com
The registration ID is generated by the device; if the device did not generate that specific key (which will change when the application requests it) then it will fail.  Secondly; your account type needs to be specified correctly note the "HOSTED_OR_GOOGLE".  This means that if you have a google account aka gmail (google); or if you have a company account that is for the google apps (hosted).  So that is another area that is wrong in the response.  You also do not need to be sending the Content-Type header here.

There are just several errors; you might want to take a look at the documentation again.  If you want to post your code again please use something like: gist.github.com and format it please.
Reply all
Reply to author
Forward
0 new messages