开发者

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

开发者 https://www.devze.com 2023-03-13 02:56 出处:网络
I create an application which appears as a tab on fan page. The administrator of the fan page开发者_如何学C give me the permission manage_pages and then the tab of my application is added to his fan p

I create an application which appears as a tab on fan page. The administrator of the fan page开发者_如何学C 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.


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']; 
      }   
   }
}


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']; 
        }   
    }
}
0

精彩评论

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