android - GoogleCloudMessaging PHP script always returning invalidregistration -
i know there lots of posts same issue, after read of them not find reason of problem.
i wrote gcm client register device receive messages server. working , can store registration id in database.
my problem in server side. i'm using script found somewhere googling, receive error result:
{"multicast_id":7341760174206782539,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"invalidregistration"}]}
the php code (i'm using browser api instead of server api told on tutorial, trying both keys returns same message):
<?php // replace real browser api key google apis $apikey = "aizasyacln4edhszw30xcmypqomz_gcrcc1ifjy"; // replace real client registration ids $registrationids = array( "apa91bedf1w4dqtsuqpt1jhhwepvrpxzb1yrpl3rvtkrvxfzxfg2-yl-pwhorsnmsnkqywq8g90ycgeboqcjgqu8cnja0n7mowf8bhmhhas4ty46pptx8yh6esasqvu3jtmmb-p0ma90ebg0rsqqbuh3ax895kxiti3lcigoyqrfe5pzq"); // message sent $message = "this test"; // set post variables $url = 'https://android.googleapis.com/gcm/send'; $fields = array( 'registration_ids' => $registrationids, 'data' => array( "message" => $message ), ); $headers = array( 'authorization: key=' . $apikey, 'content-type: application/json' ); // open connection $ch = curl_init(); // set url, number of post vars, post data curl_setopt( $ch, curlopt_url, $url ); curl_setopt( $ch, curlopt_post, true ); curl_setopt( $ch, curlopt_httpheader, $headers); curl_setopt( $ch, curlopt_returntransfer, true ); curl_setopt( $ch, curlopt_postfields, json_encode( $fields ) ); // execute post $result = curl_exec($ch); // close connection curl_close($ch); echo $result; ?>
i put real ids , key see if i'm doing right. ideas?
i had same problem couple of minutes ago.
change
$fields = array( 'registration_ids' => $registrationids, 'data' => array( "message" => $message ), );
to this:
$fields = array( 'registration_ids' => array($registrationids), 'data' => array( "message" => $message ), );
Comments
Post a Comment