Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Zend framework从PHP服务器接收到HttpResponse 400_Php_Android_Zend Framework_Google Cloud Messaging - Fatal编程技术网

使用Zend framework从PHP服务器接收到HttpResponse 400

使用Zend framework从PHP服务器接收到HttpResponse 400,php,android,zend-framework,google-cloud-messaging,Php,Android,Zend Framework,Google Cloud Messaging,我试图使用带有Zend framework的PHP服务器向我的android应用程序发送推送通知,但我得到的HttpResponse为:请求无法解析为JSON或包含无效字段,错误代码为400。 我使用了Zend framework演示中给出的服务器代码,如下所示: <?php require_once 'Zend/Mobile/Push/Gcm.php'; require_once 'Zend/Mobile/Push/Message/Gcm.php'; $regId = $_POST["

我试图使用带有Zend framework的PHP服务器向我的android应用程序发送推送通知,但我得到的HttpResponse为:请求无法解析为JSON或包含无效字段,错误代码为400。 我使用了Zend framework演示中给出的服务器代码,如下所示:

<?php
require_once 'Zend/Mobile/Push/Gcm.php';
require_once 'Zend/Mobile/Push/Message/Gcm.php';

$regId = $_POST["registrationid"];

$message = new Zend_Mobile_Push_Message_Gcm();
$message->setId(time());
$message->addToken($regId);
$message->setData(array(
    'foo' => 'bar',
    'bar' => 'foo',
));

$gcm = new Zend_Mobile_Push_Gcm();
$gcm->setApiKey('my api key');

try {
    $response = $gcm->send($message);
} catch (Zend_Mobile_Push_Exception $e) {
    // all other exceptions only require action to be sent or implementation of exponential backoff.
    die($e->getMessage());
}

// handle all errors and registration_id's
foreach ($response->getResults() as $k => $v) {
    if ($v['registration_id']) {
        printf("%s has a new registration id of: %s\r\n", $k, $v['registration_id']);
    }
    if ($v['error']) {
        printf("%s had an error of: %s\r\n", $k, $v['error']);
    }
    if ($v['message_id']) {
        printf("%s was successfully sent the message, message id is: %s", $k, $v['message_id']);
    }
}

我手头没有确切的URL,我正在手机上尝试,但最近我在博客中提到了这一点。看见
您需要的是使用浏览器API密钥,而不是服务器API密钥。不要问为什么,但谷歌的文档似乎有错误

编辑:这是我最近从另一个类似问题得到的答案的链接: