我的Facebook页面上有Facebook实时订阅的问题。
当我发布订阅时,我从facebook收到有关它的消息给我的回电网址。 代码:
$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页面添加帖子/对话时,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));
}
感谢您的帮助!
答案 0 :(得分:1)
答案 1 :(得分:0)
/ {your-app-id} /订阅的输出是什么?
根据您订阅的代码/对话需要read_page_mailboxes权限。您可能希望首先尝试使用简单的页面订阅源订阅,看看是否有效。
自昨天以来,RTU更新似乎已恢复正常,但删除您的订阅和重新订阅也可能值得一试,因为您可能在昨天RTU遇到问题时订阅了黑洞。答案 2 :(得分:0)
我在Facebook开发者论坛的朋友们的帮助下找到答案:)
我的订阅代码和回调代码很好。但要获得对话或提供对话是不够的。我必须使用graph api中的请求将我的应用程序添加到我的页面作为subscribed_app: POST {页-ID} / subscribed_apps
此操作的文档是: https://developers.facebook.com/docs/graph-api/reference/page/subscribed_apps/