0

im getting mismatch senderid error.

in gcm, i double checked the sender id as client app project id and api_key.

My code is,

    $ids = array( 'APA91bFDc......._p' );
    $data = array( 'message' => 'Hello World!' );
    $apiKey = 'AIzaSyA0_CFcI.........saGySJBE';
    $url = 'https://gcm-http.googleapis.com/gcm/send';
    $sender_id = '1063000000016';

    $post = array(
                    'registration_ids'  => $ids,
                    'data'              => $data,
                    );

    $headers = array( 
                        'Authorization: key=' . $apiKey,
                        'Sender: id=' .$sender_id,
                        'Content-Type: application/json'
                    );

    $ch = curl_init();
    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( $post ) );

    $result = curl_exec( $ch );

    if ( curl_errno( $ch ) )
    {
        echo 'GCM error: ' . curl_error( $ch );
    }

    curl_close( $ch );     
    echo $result;

my response is

 {"multicast_id":7107329859481637548,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}

why i'm facing the problem?

I refered the previous questions like, GCM Sender Id Mismatch, Android C2DM sender id, Unique SMS sender id? and etc

edit

I just added the sender id myself to the headers. where to mention the sender id and how to mention in php

Community
  • 1
  • 1
m2j
  • 1,152
  • 5
  • 18
  • 43
  • Possible duplicate of [Why do I get "MismatchSenderId" from GCM server side?](http://stackoverflow.com/questions/11313342/why-do-i-get-mismatchsenderid-from-gcm-server-side) – Marcinek Feb 04 '16 at 18:42
  • @Marcinek,.. i'm using the project id as sender id & api key, which is from the `key for server app` – m2j Feb 04 '16 at 19:21
  • When I use similar code in ASP, I only use the `API key` (39 char alphanumeric) only. My app uses the `sender id` (12 digit number) only. In GCM's terminology, `project ID` is just a name you invent for convenience when using the developer's console website. I've never passed that in code. – Magnus Smith Feb 10 '16 at 22:01

0 Answers0