1

I am migrating from C2DM to GCM. I followed the steps in the migration document, but am not sure how I can push a test message in a terminal shell window. Is it just like the C2DM method, or not?

Carl Anderson
  • 3,446
  • 1
  • 25
  • 45
vanvocel
  • 11
  • 1
  • Just did this migration myself. It was quite straightforward using the `GoogleCloudMessaging` No it'not like C2DM it's been slipstreamed easier to use. Download some sample and learn the Google Play service "way" and from there do your terminal shell window – Erik Oct 02 '13 at 22:08

2 Answers2

0

It seems that the official documentation is not yet completely provided by Google (see here). At least this is what I found out when trying to create a new "App Engine Connected Android Project" in the new version of GPE. However they "plan to release the next version end of July". I think that, by then, they should have a complete documentation, how to proceed with the migration you are doing.

Community
  • 1
  • 1
Xtoph.at
  • 195
  • 3
  • 11
0

Here's a small amount of php that you can use, just put this into a php file ("gcm-push.php") then run like:

php gcm-push.php

You'll need to set your device registration id and the GCM API key.

<?php
// Message to send
$message = "the test message";

// Put your device token here (without spaces):
$registrationId = "DEVICE_REG_ID";

// GCM API Key
$apiKey = "INSERT_YOUR_KEY";

$headers = array("Content-Type:" . "application/json", "Authorization:" . "key=" . $apiKey);
$data = array(
    'data' => $message,
    'registration_ids' => array($registrationId)
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send");
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
error_log(json_encode($data));
$response = curl_exec($ch);
curl_close($ch);
error_log($response); 
Michael
  • 3,776
  • 1
  • 16
  • 27