I have implemented a C2DM client that requests the registration id from C2DM server. Once application gets registration id, applications stores device id and registration id in server database. I have implemented a PHP Server, but when ever i try to post message i get Error=MissingRegistration.
PHP Server Code
$url = 'https://www.google.com/accounts/ClientLogin';
$body = 'Email=senderid@gmail.com&Passwd=password&accountType=GOOGLE&source=MyLittleExample&service=ac2dm';
$c = curl_init ($url);
curl_setopt ($c, CURLOPT_POST, true);
curl_setopt ($c, CURLOPT_POSTFIELDS, $body);
curl_setopt ($c, CURLOPT_RETURNTRANSFER, true);
$page = curl_exec ($c);
$p = explode("Auth=",$page);
curl_close ($c);
$url = 'https://android.apis.google.com/c2dm/send';
$param = // Get Registration id from my sql
$mtype = 'important';
$msg = 'Hello';
$len = strlen($param);
echo $len;
function sendMessageToPhone($authCode, $deviceRegistrationId, $msgType, $messageText) {
$headers = array('Content-length:300','Authorization: GoogleLogin auth='.$authCode );
$data = array(
'registration_id' => $deviceRegistrationId,
'collapse_key' => $msgType,
'data.message' => $messageText //TODO Add more params with just simple data instead
);
$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);
return $response;
}
$data = sendMessageToPhone($p[1],$param,$mtype,$msg);
var_dump($data);
According to the document Error=MissingRegistration occurs if there is no registration_id parameter in Post request. I even tried to run application by hard coding the Registration Id. Any help greatly appreciated. Thank You.
Aha! And here comes the possible solution (taking from a thread regarding notifications from another language I do not know): https://stackoverflow.com/a/8339611/1108032. Please read what he stated solved his issue. For me it looks like something like that should be failing you, because code-wise your code seems ok.