如何在没有facebook SDK的情况下使用curl向用户发送facebook通知


How to send a facebook notification to a user using curl without facebook SDK

我用Facebook的以下输出尝试了以下操作,因为这需要一篇帖子。

$ch = curl_init('https://graph.facebook.com/appUserId/notifications?access_token=*****&href=index.php&template=test');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$response = curl_exec($ch);
var_dump($response);
var_dump(json_decode($response));

然后,我得到了以下内容,我可能做错了什么?

string '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
   xml:lang="en" lang="en" id="facebook">
  <head>
    <title>Facebook | Error</title>
    <meta http-equiv="Content-Type"  content="text/html; charset=utf-8" />
    <meta http-equiv="Cache-Control" content="no-cache" />
    <meta name="robots"              content="noindex,nofollow" />
    <style type="text/css">
      html, body {
        margin:      '... (length=2131)
null

您可以使用他们的原生Facebook PHP-SDK:轻松完成此操作

https://developers.facebook.com/docs/php/gettingstarted/4.0.0

以下是用于发送通知的API方法文档:https://developers.facebook.com/docs/graph-api/reference/v2.1/user/notifications

PHP-SDK:的使用示例

/* PHP SDK v4.0.0 */
/* make the API call */
$request = new FacebookRequest(
  $session,
  'POST',
  '/{user-id}/notifications',
  array (
    'href' => '/testurl?param1=value1',
    'template' => 'This is a test message',
  )
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */