Facebook API Page/Feed 的实时更新无响应
Facebook API Real Time updates for Page/Feed no response
我的 Facebook 页面上的 Facebook 实时订阅有问题。
当我 POST 订阅时,我从 facebook 收到关于它的消息到我的回电 url。
代码:
$session = new FacebookSession('<APP ACCESS TOKEN>');
$request = new FacebookRequest(
$session,
'POST',
'/<APP ID>/subscriptions',
array(
'object' => 'page',
'callback_url' => 'http://*************/facebook/callback.php',
'fields' => 'conversation', // a try 'feed' to
'verify_token' => '<VERIFY TOKEN>',
)
);
$response = $request->execute();
但是当有人在我的 fb 页面上添加 post/conversation 时,facebook 不会向我发送任何数据。
callback.php代码:
<?php
// Insert the path where you unpacked log4php
include('log4php/Logger.php');
// Tell log4php to use our configuration file.
Logger::configure('config.xml');
// Fetch a logger, it will inherit settings from the root logger
$log = Logger::getLogger('myLogger');
// Start logging
$log->warn($_REQUEST); // Logged because WARN >= WARN
require_once __DIR__ . '/facebook-php-sdk-v4-5.0-dev/src/Facebook/autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\Authentication\AccessToken;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;
//define('VERIFY_TOKEN', '*******');
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'GET' && $_GET['hub_mode'] == 'subscribe' && $_GET['hub_verify_token'] == '<VERIFY TOKEN>') {
echo $_GET['hub_challenge'];
$log->warn($_GET);
$log->warn($_POST);
} else if ($method == 'POST') {
$updates = json_decode(file_get_contents("php://input"), true);
// Here you can do whatever you want with the JSON object that you receive from FaceBook.
// Before you decide what to do with the notification object you might aswell just check if
// you are actually getting one. You can do this by choosing to output the object to a textfile.
// It can be done by simply adding the following line:
// file_put_contents('/filepath/updates.txt',$updates, FILE_APPEND);
$log->warn($updates);
$log->warn($_GET);
$log->warn($_POST);
error_log('updates = ' . print_r($obj, true));
}
感谢您的帮助!
Facebook 支持目前存在一个未解决的错误:
所以这可能是暂时的问题...
/{your-app-id}/subscriptions 的输出是什么?
根据您的代码,您订阅了需要 read_page_mailboxes 权限的 /conversations。您可能想先尝试简单的页面订阅,看看是否可行。
RTU 更新似乎从昨天开始恢复正常,但是删除您的订阅并重新订阅也值得一试,因为昨天 RTU 出现问题时您可能订阅了一个黑洞。
我在 facebook 开发者论坛朋友的大力帮助下找到了答案:)
我的订阅和回调代码很好。但是仅仅获得对话或喂养它是不够的。我必须使用图表 api 中的请求将我的应用程序作为 subscribed_app 添加到我的页面:
POST
{page-id}/subscribed_apps
此操作的文档在:
https://developers.facebook.com/docs/graph-api/reference/page/subscribed_apps/
我的 Facebook 页面上的 Facebook 实时订阅有问题。
当我 POST 订阅时,我从 facebook 收到关于它的消息到我的回电 url。 代码:
$session = new FacebookSession('<APP ACCESS TOKEN>');
$request = new FacebookRequest(
$session,
'POST',
'/<APP ID>/subscriptions',
array(
'object' => 'page',
'callback_url' => 'http://*************/facebook/callback.php',
'fields' => 'conversation', // a try 'feed' to
'verify_token' => '<VERIFY TOKEN>',
)
);
$response = $request->execute();
但是当有人在我的 fb 页面上添加 post/conversation 时,facebook 不会向我发送任何数据。
callback.php代码:
<?php
// Insert the path where you unpacked log4php
include('log4php/Logger.php');
// Tell log4php to use our configuration file.
Logger::configure('config.xml');
// Fetch a logger, it will inherit settings from the root logger
$log = Logger::getLogger('myLogger');
// Start logging
$log->warn($_REQUEST); // Logged because WARN >= WARN
require_once __DIR__ . '/facebook-php-sdk-v4-5.0-dev/src/Facebook/autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\Authentication\AccessToken;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;
//define('VERIFY_TOKEN', '*******');
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'GET' && $_GET['hub_mode'] == 'subscribe' && $_GET['hub_verify_token'] == '<VERIFY TOKEN>') {
echo $_GET['hub_challenge'];
$log->warn($_GET);
$log->warn($_POST);
} else if ($method == 'POST') {
$updates = json_decode(file_get_contents("php://input"), true);
// Here you can do whatever you want with the JSON object that you receive from FaceBook.
// Before you decide what to do with the notification object you might aswell just check if
// you are actually getting one. You can do this by choosing to output the object to a textfile.
// It can be done by simply adding the following line:
// file_put_contents('/filepath/updates.txt',$updates, FILE_APPEND);
$log->warn($updates);
$log->warn($_GET);
$log->warn($_POST);
error_log('updates = ' . print_r($obj, true));
}
感谢您的帮助!
Facebook 支持目前存在一个未解决的错误:
所以这可能是暂时的问题...
/{your-app-id}/subscriptions 的输出是什么?
根据您的代码,您订阅了需要 read_page_mailboxes 权限的 /conversations。您可能想先尝试简单的页面订阅,看看是否可行。
RTU 更新似乎从昨天开始恢复正常,但是删除您的订阅并重新订阅也值得一试,因为昨天 RTU 出现问题时您可能订阅了一个黑洞。
我在 facebook 开发者论坛朋友的大力帮助下找到了答案:)
我的订阅和回调代码很好。但是仅仅获得对话或喂养它是不够的。我必须使用图表 api 中的请求将我的应用程序作为 subscribed_app 添加到我的页面: POST {page-id}/subscribed_apps
此操作的文档在: https://developers.facebook.com/docs/graph-api/reference/page/subscribed_apps/