-1

Who can tell me how can I get the "$registrationIDs = array( "reg id1","reg id2");", mentioned in the following code, which is posted here GCM with PHP (Google Cloud Messaging)

<?php
           // Replace with real server API key from Google APIs  
            $apiKey = "your api key";    

              // Replace with real client registration IDs
           $registrationIDs = array( "reg id1","reg id2");

          // Message to be sent
         $message = "hi Shailesh";

         // 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 the 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 ) );

         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     //     curl_setopt($ch, CURLOPT_POST, true);
       //     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;
          //print_r($result);
           //var_dump($result);
       ?>
Community
  • 1
  • 1
Susheng
  • 1
  • 1

1 Answers1

0

You need to build a Web page that the app can use to communicate the RegID, once the app receives the RegID. You'll have to introduce some kind of server-side storage (a database, a file) that the RegID will be stored in.

Depending on your business, you might want to accept some additional parameters. POST form is a good place for those.

Then in the app, once you get the RegID, you perform a HTTP request, passing the RegID along. Word of caution: don't call HttpClient from the main thread. Use an AsyncTask, or spin a new Thread.

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
  • Thank you very much! I have solved the problem. It is my first time to put a post here and also the start of my coding life. – Susheng Oct 02 '12 at 12:26