【问题标题】:How to send a facebook notification to a user using curl without facebook SDK如何在没有 facebook SDK 的情况下使用 curl 向用户发送 facebook 通知
【发布时间】:2014-10-07 11:13:30
【问题描述】:

我使用 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

【问题讨论】:

    标签: php facebook http facebook-graph-api curl


    【解决方案1】:

    您可以使用他们的原生 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 */
    

    【讨论】:

    猜你喜欢
    • 2016-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-03
    相关资源
    最近更新 更多