ScyTer | Дата: Пятница, 15.05.2015, 11:18 | Сообщение # 1 |
Лорд-джедай
Группа: Администраторы
Сообщений: 1167
Награды: 0
Репутация: 1
Статус: Offline
| In Developer Console https://play.google.com/apps/publish?hl=en in tab Game Services add new game (button "Add new game"). Fill Game Title and category.
Then in Console https://console.developers.google.com/project you'll see new Project:
Open it. This is your new project info:
Project number you need to fill in Android App to get your registrationID so you can get GCM from this game: registrationID = gcm.register(projectNumber);
Then open APIs tab and selec Cloud Messaging for Android:
Press Enable API, so you'll get such result:
Open Credentials and then press "Create new key" button for public api access:
Choose "Server key":
Then you can fill IPs witch avaliable to send GCM notifications (I set field empty, so any IP can send notification):
Then set API key on your server. Also allowed IPs can be edit any time:
Server example: <?php $api_key = 'AIzaSyAzC2eZQB6ATqOiJigVh7IaR29jWcxuM2M';
$registrationIDs= array("APA91bGetPCtbLbTdyorzlK-0BzkBc0sc1O-ZiFPSt90IceRS_BYrdFxxMBr9y1ZcvCihwm51ZcXnctcHDhBGYG07iCLfXDN_U8sgd7vR682c__FESDuQteTifoXIFSrgH9tM -LrSQ_0DVBJh"); //registrationIDs of android devices $message = array("Test message!"); // Message to be sent
// Set POST variables $url = 'https://android.googleapis.com/gcm/send';
$fields = array( 'registration_ids' => $registrationIDs, 'data' => array( "message" => $message ) // tut lubye polya mogut byt' ); $headers = array( 'Authorization: key='. $api_key, '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( $fields)); $result = curl_exec($ch); curl_close($ch); ?>
|
|
| |