Php GCM拒绝访问
我正在使用GCM向android设备发送消息。它在localhost中工作得非常好。但当我尝试使用远程服务器时,GCM不允许服务器访问它。它显示为“连接失败:权限被拒绝”。我认为,对于本地主机和远程服务器使用相同的api密钥是一个问题。我还更改了api密钥。谁能解释一下这有什么问题吗。谢谢GCM代码是这样的Php GCM拒绝访问,php,android,google-cloud-messaging,Php,Android,Google Cloud Messaging,我正在使用GCM向android设备发送消息。它在localhost中工作得非常好。但当我尝试使用远程服务器时,GCM不允许服务器访问它。它显示为“连接失败:权限被拒绝”。我认为,对于本地主机和远程服务器使用相同的api密钥是一个问题。我还更改了api密钥。谁能解释一下这有什么问题吗。谢谢GCM代码是这样的 <?php class GCM { //put your code here // constructor function __construct() {
<?php
class GCM {
//put your code here
// constructor
function __construct() {
}
/**
* Sending Push Notification
*/
public function send_notification($registatoin_ids, $message) {
// include config
include_once './config.php';
// 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'
);
// Open connection
$ch = curl_init();
// 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) {
die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
echo $result;
}
}
?>
清除谷歌控制台服务器密钥页上的所有IP地址,也许这会解决您的问题。如果没有,请在评论中联系
检查您的
GOOGLE\u API\u密钥
。我想这是无效的。还要检查在部署的位置是否启用了curlit@SunilMishra:我为它创建了一个新密钥。但仍然会犯错误。@AnirudhaAgashe:如何检查它。请告诉我,看看这里