当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Facebook API Real Time updates for Page/Feed no response

问题描述:

I have a problem with Facebook Real-time subscription from my facebook page.

When I POST a subscription, i get the message from facebook about it to my call back url.

Code:

$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();

BUT when someone add a post/conversation to my fb page, facebook don't send me any data.

callback.php code:

<?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));

}

Thank you for your help !

网友答案:

There is currently an open bug with Facebook support:

  • https://developers.facebook.com/bugs/709097499224897/

So it's possible that this is a temporary issue...

网友答案:

What's the output of /{your-app-id}/subscriptions?

According to your code you subscribed to /conversations which requires read_page_mailboxes permissions. You probably want to try a simple page feed subscription first to see if this works.

RTU updates seem to be back to normal since yesterday, but deleting your subscriptions and re-subscribing might be worth a try, too, since you probably subscribed to a black hole when RTU had issues yesterday.

网友答案:

I find answer with a big help from facebook developers forum friends :)

My code to make subscription and callback code is good. But to get conversations or feed it is not enough. I have to add my app to my page as a subscribed_app using request in graph api: POST {page-id}/subscribed_apps

the docs for this operation is on: https://developers.facebook.com/docs/graph-api/reference/page/subscribed_apps/

分享给朋友:
您可能感兴趣的文章:
随机阅读: