相关疑难解决方法(0)

Google GCM服务器返回未经授权的错误401

我正在使用GCM服务从服务器推送信息.如果我使用浏览器密钥,则显示成功的表格:{"multicast_id":4849013215736515938,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0: 1348742583011905%2adac3a0f9fd7ecd"}]} 但我没有在设备上收到任何通知.如果我使用服务器密钥,它会显示Unauthorized Error 401.我的代码如下所示:

$apiKey = "xxxxx";
$registrationIDs = array("xxxxxxxx");
$message = "testing Process";
$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'
        );
$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_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode($fields) );

$result = …
Run Code Online (Sandbox Code Playgroud)

php android json google-cloud-messaging

30
推荐指数
3
解决办法
7万
查看次数

标签 统计

android ×1

google-cloud-messaging ×1

json ×1

php ×1