谷歌GCM服务器返回未经授权错误401 [英] Google GCM server returns Unauthorized Error 401

查看:2679
本文介绍了谷歌GCM服务器返回未经授权错误401的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用GCM服务,推动从服务器的信息。如果我使用的浏览键则显示sucess mesaage为: {"multicast_id":4849013215736515938,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1348742583011905%2adac3a0f9fd7ecd"}]} 但我没有得到设备的任何通知。 如果我使用服务器密钥就说明未经授权错误401 。我的code如下所示:

I am using GCM services to push information from server. If I use browser key it shows the sucess mesaage as : {"multicast_id":4849013215736515938,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1348742583011905%2adac3a0f9fd7ecd"}]} but i did not get any notifications on device. And if I use server key it shows Unauthorized Error 401. My code is shown below:

$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 = curl_exec($ch);
if(curl_errno($ch)){ echo 'Curl error: ' . curl_error($ch); }
curl_close($ch);
echo $result;

请帮我这个问题。先谢谢了。

Please help me for this issue. Thanks in advance.

推荐答案

你白名单服务器的IP?这并不完全是为浏览器键必要的,但它是对服务器密钥。

Did you whitelist the IP of your server? This is not necessary by default for the browser key, but it is for the server key.

您可以检查在这里:

HTTPS://$c$c.google.com/apis/console/#project:[您的项目编号]:访问

https://code.google.com/apis/console/#project:[YOUR PROJECT NUMBER]:access

这篇关于谷歌GCM服务器返回未经授权错误401的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆