【问题标题】:Facebook API Real Time updates for Page/Feed no responseFacebook API 实时更新页面/Feed 无响应
【发布时间】:2015-12-11 18:51:58
【问题描述】:

我的 Facebook 页面上的 Facebook 实时订阅有问题。

当我发布订阅时,我从 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 页面添加帖子/对话时,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));
}

感谢您的帮助!

【问题讨论】:

    标签: php facebook facebook-graph-api real-time facebook-requests


    【解决方案1】:

    Facebook 支持目前存在一个未解决的错误:

    所以这可能是一个暂时的问题......

    【讨论】:

    • 是的,这是可能的,我必须等待然后检查。感谢您的回复;)
    • 问题已在 facebook 支持上得到修复,但当我创建新订阅时,我的回调仅获取 [hub_mode]、[hub_challange] 和 [hub_verify_token] 的数据。当我的页面(cmets、posts 或 message)发生变化时,回调是空的......
    【解决方案2】:

    /{your-app-id}/subscriptions 的输出是什么?

    根据您订阅 /conversations 的代码,这需要 read_page_mailboxes 权限。您可能想先尝试一个简单的页面订阅订阅,看看是否可行。

    RTU 更新似乎从昨天开始恢复正常,但删除您的订阅并重新订阅可能也值得一试,因为您可能在昨天 RTU 出现问题时订阅了黑洞。

    【讨论】:

      【解决方案3】:

      我在 facebook 开发者论坛朋友的大力帮助下找到了答案 :)

      我的订阅和回调代码很好。但要获得对话或提供信息是不够的。我必须使用图形 api 中的请求将我的应用程序作为 subscribed_app 添加到我的页面: 邮政 {page-id}/subscribed_apps

      此操作的文档已启用: https://developers.facebook.com/docs/graph-api/reference/page/subscribed_apps/

      【讨论】:

        猜你喜欢
        • 2016-03-22
        • 2015-05-09
        • 2015-04-05
        • 1970-01-01
        • 2015-02-08
        • 1970-01-01
        • 2014-02-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多