gian sta
gian sta

Reputation: 13

Facebook Real Time Subscriptions Throws Exception Even when challenge is answered

I'm trying to subscribe from my app to Real Time Subscription of Facebook using v2.4 Graph API (after creating a callback function in fbcallback.php) using the code below from my index.php page (the appid and IP address obviously fake in this post):

try {
        $response=$fb->sendRequest('POST','/1111/subscriptions',
            array(
            'object' => 'user',
        'callback_url' => 'http://111.111.111.111/fbcallback.php',
        'fields' => 'first_name',
        'verify_token' => 'thisisaverifystringtestuser',
            )
        );
    $graphNode = $response->getGraphNode();
    }catch (Facebook\Exceptions\FacebookSDKException $e) { 
echo "exception:" . $e->getMessage();  } 

While i'm sure from callback log that Facebook reaches my callback function and i use in it the code below:

<?php
define('VERIFY_TOKEN', 'thisisaverifystringtestuser');                                    
$method = $_SERVER['REQUEST_METHOD'];                             

if ($method == 'GET' && $_GET['hub_mode'] == 'subscribe' &&       
    $_GET['hub_verify_token'] == VERIFY_TOKEN) {
  echo $_GET['hub_challenge'];
 } 
 ?> 

i get the Message from my index page code looking like this: exception:(#2201) response does not match challenge, expected value = '866531638', received='866531638'

Anyone encountered it?

P.S I created a test user from the app dashboard roles and configured him to subscribe to app on creation and also got (but not used) an access token for this user from dashboard also.....since i can't denote a specific user during the subscription proccess from my php code i expect (or wish) this user to be subscribed by my php code...am i wrong?

Upvotes: 1

Views: 27

Answers (1)

C3roe
C3roe

Reputation: 96383

Looks like your script outputs more than just the hub_challenge value.

When I copy&paste the error message from your posting, and insert it in NotePad++, I get that part shown as

received='?866531638'
          ^

– so there seems to be some invisible/not display-able character before the actual value.

Make sure your script is saved as UTF-8 without BOM, and that it does not make any other output besides the hub_challenge value either. (That could include stuff outside of <?php … ?> tags as well.)

Upvotes: 1

Related Questions