1

i want to use push notification for android device i try below code with google API key "AIzaSyCBpVn9J2TWxPZDqyilCssUh5dbphQQtWE" and device register id "APA91bGiZr2BAqkwqQrsxCfXftzVnUGaWnBbI-NYtT3i3vpQC_wwMcLZDoJx-04YHUHUf0NKp3Sjnwx_Rx-u-3fAZOTVFI9oRp2z" but it gives "Unauthorized Error 401" error..

<?php

define( 'API_ACCESS_KEY', 'AIzaSyCBpVn9J2TWxPZDqyilCssUh5dbphQQtWE');


$registrationIds = array("APA91bGiZr2BAqkwqQrsxCfXftzVnUGaWnBbI-NYtT3i3vpQC_wwMcLZDoJx-04YHUHUf0NKp3Sjnwx_Rx-u-3fAZOTVFI9oRp2z");

// prep the bundle
$msg = array
(
    'message'     => 'here is a message. message',
    'title'        => 'This is a title. title',
    'subtitle'    => 'This is a subtitle. subtitle',
    'tickerText'    => 'Ticker text here...Ticker text here...Ticker text here',
    'vibrate'    => 1,
    'sound'        => 1,
    'largeIcon'    => 'large_icon',
    'smallIcon'    => 'small_icon'
);

$fields = array
(
    'registration_ids'     => $registrationIds,
    'data'            => $msg
);

$headers = array
(
    'Authorization: key=' . API_ACCESS_KEY,
    'Content-Type: application/json'
);

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
curl_setopt( $ch,CURLOPT_POST, 1 );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );

echo $result;
?>
dtanwar
  • 68
  • 9
  • Check here http://stackoverflow.com/questions/25859898/sending-push-notifications-to-multiple-android-devices-using-gcm – Sumant Jan 28 '16 at 09:08
  • refer this : http://stackoverflow.com/questions/12619759/google-gcm-server-returns-unauthorized-error-401 – Mr. Engineer Jan 28 '16 at 09:10

1 Answers1

0

If You want to check your UDID and browser key is work correctly than you can check by this.

Vishal Patoliya ツ
  • 3,170
  • 4
  • 24
  • 45