开发者

Retrieving page's tabs using a batch request

I'm desperately trying to retrieve page's tabs using a batch request (with Facebook PHP SDK) but Facebook keeps returning the same error. Here's my code:

$query = array(
    array('method' => 'GET', 'relative_url' => '/'.$page_id, 'name' => 'get-page' ),
    array('method' => 'GET', 'relative_url' => '/'.$page_id.'/tabs', 'access_token' => '{result=get-page:$.data.0.access_token}'));

$res = $facebook->api('/?batch=' . json_encode($query), 'POST');

And here's the result:

array开发者_Python百科
    'code' => int 403
    'headers' =>
        array 
            ...
    'body' => string '{"error":{"type":"OAuthException","message":"(#210) Subject must be a page."}}

I tried without the batch request, and it works just fine. I assume it comes from a bug in the Facebook API, but maybe someone found a workaround.

Thank you if anyone can help me!

EDIT:

Because no one seems to find a solution to this issue:

Does anyone know how fetch all the tabs from a fan page in a single request?


assuming you are logged in and have an access token in hand to view the pages here's an excerpt that you should try before moving forward:

// get all the pages        
$pages = $fb->api('/me/accounts');
$pages = $pages['data'];

// assume there is at least one page
$workpage = $pages[0];

// get all the tabs for this page
$tabs = $fb->api("/{$workpage['id']}/tabs", array('access_token'=>$workpage['access_token'] ));
print_r($tabs);

as for the 'batch' request that you need, you can add loops to the above code and get creative.


Thank you for your help Fakeer! Actually I already tried your solution, and it worked just fine, but I wanted to limit the number of requests...

And finally I found what went wrong with my request. Here is the correct version:

$query = array(
    array('method' => 'GET', 'relative_url' => '/'.$page_id.'?fields=access_token', 'name' => 'get-page' ),
    array('method' => 'GET', 'relative_url' => '/'.$page_id.'/tabs', 'access_token' => '{result=get-page:$.access_token}'));

$res = $facebook->api('/?batch=' . json_encode($query), 'POST');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜