简体   繁体   中英

How can I get the name of every Facebook page separately with the Graph API?

I want to display all the pages the user is admin of with the new Graph API in Facebook. What I do is:

       $queries = '{
        "page_admin_ids" : "SELECT page_id FROM page_admin WHERE uid = ' . $uid . '",
        "page_name_and_id" : "SELECT name FROM page WHERE page_id IN (SELECT page_id FROM #page_admin_ids)"
       }';

        $data = array(
            'method' => 'fql.multiquery', 
            'queries' => $queries,
            'callback'  => ''
        );

        $fqlResult = $facebook->api($data);
        print_r($fqlResult); 

This code works and all the data of the Array are displayed in an Array format. I want to use each of them, each of the page name, separately and add it to my html code. How can I get the first element for example of the results?

Thanks in advance

If you're using the new Facebook PHP SDK then you should be able to do the following:

<?php
$facebook  = new Facebook(array(
    'appId'  => $config['appid'],
    'secret' => $config['appsecret'],
    'cookie' => true,
));

$session = $facebook->getSession();
$user = null;
if ($session) {
    try {
        $user = $facebook->api('/me');
    }
    catch (FacebookApiException $e) {
        error_log($e);
    }
}
if (!$user) {
    $loginUrl = $facebook->getLoginUrl(array(
        'canvas' => 1,
        'fbconnect' => 0,
        'req_perms' => 'manage_pages', // request extended perms. here
        'next' => "http://www.example.com/",
        'cancel_url' => "http://www.example.com/",
    ));
    echo '<fb:redirect url="' . $loginUrl . '" />';
}

$pages = $facebook->api('/me/accounts');
...

This gives me a list of pages I'm an administrator of on Facebook.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM