Luis
Luis

Reputation: 3277

How can I use 'manage_pages' permission with the SDK on Facebook?

I create an application which appears as a tab on fan page. The administrator of the fan page give me the permission manage_pages and then the tab of my application is added to his fan page.

The problem is that I didn't find any example code on how to use this permission with the PHP SDK. I looked in the file base_facebook.php of the SDK, and I guess that I should using the function getApiUrl, but I'm not sure and probably I don't know how using this function.

Upvotes: 3

Views: 5059

Answers (2)

garvidal
garvidal

Reputation: 11

You have a mistake. Is $page['name']

function get_page_access_token($page_id, $access_token, $user_id) {
    $data = curl_get_contents('https://graph.beta.facebook.com/'.$user_id.'/accounts?access_token='.$access_token);
    $pages = json_decode($data,true);
    foreach ($pages['data'] as $page) {
        if ($page['name'] == $page_id) {
            return $page['access_token']; 
        }   
    }
}

Upvotes: 1

Jeff Sherlock
Jeff Sherlock

Reputation: 3544

Now that you have the manage_pages permission, take the access token, pass it into a method like the one I've created below to get an access token to manage the page. Each page has its own access token that you need to use once you have the manage_pages permission.

function get_page_access_token($page_id, $access_token, $user_id) {
    $data = file_get_contents('https://graph.beta.facebook.com/'.$user_id.'/accounts?access_token='.$access_token);
    $pages = json_decode($data,true);
    foreach($pages['data'] as $page) {
      if($page['id'] == $page_id) {
        return $page['access_token']; 
      }   
   }
}

Upvotes: 5

Related Questions