我试图通过使用电子邮件发送简单的推送通知与pushbullet只是通过使用电子邮件并发送到链接的帐户,以避免需要帐户数据。 (见参考这里:https://docs.pushbullet.com/#pushes)在PHP中发送POST请求pushbullet API 401错误
因此我使用PHP中的非卷曲的方法,我(不仅)在这里找到: How do I send a POST request with PHP?
不幸的是我回来的错误如下:
<br />
<b>Warning</b>: file_get_contents(https://api.pushbullet.com/v2/pushes): failed to open stream: HTTP request failed! HTTP/1.0 401 Unauthorized
in <b>/path/to/function.php</b> on line <b>42</b><br />
bool(false)
将file_get_contents使用url的选项设置为“on”。
我的代码:
$pushdata = array(
"email" => $email,
"type" => "link",
"title" => "Demo Pushbullet Notification",
"body" => "You have new comment(s)!",
"url" => "http://demo.example.com/comments"
);
//Post without cURL
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n"."Authorization: Bearer <xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>\r\n",
'method' => 'POST',
'content' => http_build_query($pushdata),
),
);
$context = stream_context_create($options);
$result = file_get_contents("https://api.pushbullet.com/v2/pushes", false, $context, -1, 40000);
var_dump($result);
编辑:代码改为christopherhesse的回应,仍然无法正常工作。它也不应该要求访问令牌,因为我知道推送。我理解它是将通知从中性推送到链接的电子邮件。也许我错了,但访问令牌不能解决它。
编辑(解决):访问令牌IS需要推送通知,因为它不能用这种方法,它可以使用cURL。
这样做,谢谢。 – Pinetrax
你非常欢迎,很高兴帮助。 – nblackburn