简体   繁体   English

在创建新帖子时得到通知

[英]Get notified when new post created

I looking for a way to get notified from facebook whenever a new post has been created. 我正在寻找一种方法,以便在创建新帖子时从Facebook得到通知。 So far the only solution I've found is cron job to check every few minutes. 到目前为止,我发现的唯一解决方案是cron作业,每隔几分钟检查一次。 Don't the facebook sdk provide such method? Facebook SDK不提供这种方法吗?

Thanks 谢谢

Use Facebook Graph API Subscriptions 使用Facebook Graph API订阅

https://developers.facebook.com/blog/post/2012/01/31/how-to--subscribing-to-data-changes-using-the-real-time-updates-api/ https://developers.facebook.com/blog/post/2012/01/31/how-to--subscribing-to-data-changes-using-the-real-time-updates-api/

<?php

  $app_id = 'YOUR_APP_ID';
  $app_secret = 'YOUR_APP_SECRET';
  $app_url = 'http://YOURAPPURL';
  $fields = 'feed';
  $verify_token = 'YOURVERIFYTOKEN';

  // Fetching an App Token
  $app_token_url = 'https://graph.facebook.com/oauth/access_token?client_id='
                   .$app_id.'&client_secret='.$app_secret
                   .'&grant_type=client_credentials';
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $app_token_url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $res = curl_exec($ch);
  parse_str($res, $token);

  if (isset($token['access_token'])) {
    // Let's register a callback
    $params = array(
      'object'
        =>  'user',
      'fields'
        =>  $fields,
      'callback_url'
        // This is the endpoint that will be called when
        // a User updates the location field
        =>  $app_url . '/index.php?action=callback',
      'verify_token'
        =>  $verify_token,
    );

    curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/'
                                  .$app_id.'/subscriptions?access_token='
                                  .$token['access_token']);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    $res = curl_exec($ch);
    if ($res && $res != 'null') {
      print_r($res);
    }

    // Fetch list of all callbacks
    curl_setopt($ch, CURLOPT_POST, 0);
    $res = curl_exec($ch);
  }
  if ($res && $res != 'null') {
    print_r($res);
  }
  curl_close($ch);

?>

Some more helpful links: 一些更有用的链接:

https://developers.facebook.com/docs/graph-api/reference/app/subscriptions/ https://developers.facebook.com/docs/graph-api/reference/app/subscriptions/

https://developers.facebook.com/docs/graph-api/real-time-updates/ https://developers.facebook.com/docs/graph-api/real-time-updates/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 创建新帖子时获取用户 ID - get user id when created a new posts 创建新用户时,在POST参数中获取用户名和密码 - Getting username and password exposed in POST parameters when created a new user 在Wordpress post-new.php中创建新帖子时添加自定义php代码 - Adding custom php code when a new post is created in Wordpress post-new.php 创建新帖子时将默认分类术语分配给自定义帖子类型 - Assign default taxonomy term to custom post type when new post created 通过电子邮件将文件上传到服务器时收到通知 - Get notified when a file got uploaded to server by email 获取库存不可用的通知 - Get notified on stock unavailability 为什么当“ post”替换为“ get”时,CakePHP为什么要添加“新行”? - Why does CakePHP add New Rows when 'post' is replaced by 'get'? 如何使用Facebook API获取有关新朋友和删除朋友的通知? - How to get notified about new friends and removed friends using the Facebook API? 当我在 Wordpress 中发布新帖子时,我无法获取帖子的标签 - When I publish a new post in Wordpress, I cannot get the tags of the post 创建新文件时如何获取电子邮件警报? 交友/南国/ Centos的 - How to get email alerts when a new file is created? Cpanel/WHM/Centos
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM