你好,我正在尝试从我的PHP Web服务器向Android手机发送通知...但是我收到的响应是:
Unauthorized Error 401
以下是我的代码。
<?php $url = 'https://android.googleapis.com/gcm/send';
$device_ids = array('devise ID' );
$headers = array('Authorization: key=api key',
'Content-Type: application/json');
$t_data = array();
$t_data['message'] = array('Someone commented on your business.');
$t_json = array( 'registration_ids' => $device_ids , 'data' => $t_data );
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers );
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( $t_json ) );
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
if ($result === FALSE)
{
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
echo $result;
?>
我该如何解决这个错误
API key
。 - Mehul Joisar