Google Cloud Message (GCM) sent android is Error inValid Register
Posted
技术标签:
【中文标题】Google Cloud Message (GCM) sent android is Error inValid Register【英文标题】: 【发布时间】:2014-06-25 18:10:55 【问题描述】:我正在使用 Google 云消息 (GCM) 构建应用程序,关注文章 androidexample create app to push notify
但是当我尝试使用链接https://android.googleapis.com/gcm/send 和代码中的某些字段通过 CURL 向 Google 服务器发送通知时出现错误
function send_push_notification($registatoin_ids, $message)
echo implode($registatoin_ids);
echo implode($message);
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registatoin_ids,
'data' => $message,
);
$headers = array(
'Authorization: key=' . GOOGLE_API_KEY,
'Content-Type: application/json'
);
//print_r($headers);
// Open connection
$ch = curl_init();
//echo $ch;
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if ($result === FALSE)
echo ("RESULT ERROR :" + $ch);
die('Curl failed: ' . curl_error($ch));
// Close connection
curl_close($ch);
echo $result;
尝试发送时收到结果错误
所以,请你帮我修复或配置发送消息到服务器,我尝试制作一个应用程序将通知从服务器发送到 Android 设备, 非常感谢。
PS:对不起我的英语,再次感谢
欢
【问题讨论】:
【参考方案1】:你用的教程太旧了。
看这里:
GCMRegistrar.setRegisteredOnServer(context, true);
此类已弃用
现在你应该使用 Google Cloud Messaging
【讨论】:
以上是关于Google Cloud Message (GCM) sent android is Error inValid Register的主要内容,如果未能解决你的问题,请参考以下文章
GCM(Google Cloud Messaging)推送完全解析
Google Cloud端点模块与GCM的Google云端模块?
AGSXMPP 与 Google Cloud Connection (GCM) 断开连接
获取来自 Google Cloud Messaging 的 json 数据