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;
?>