如何通过应用程序在Facebook上作为管理员分享链接?

时间:2012-03-24 22:08:59

标签: php facebook

如何通过应用程序以管理员身份在Facebook页面上分享链接?

示例: like tihs

1 个答案:

答案 0 :(得分:1)

花了大约2个小时为你工作。很高兴;)

require_once("facebook.php");
    $facebook = new Facebook(array(
        'appId'  => 'YOUR APP ID',
        'secret' => 'YOUR APP SECRET',
    ));
    $pageID = 123456789; //YOUR PAGE ID HERE

    $user_id = $facebook->getUser();
    if($user_id != false && $user_id != 0) {
        //user is logged in.
        $response = $facebook->api('me/accounts');
        foreach ($response['data'] as $key => $val) {
            if ($val['id'] == $pageID) {
                $page_access_token = $val['access_token'];
                //Below is the API Call for the posting to the page's wall.
                $api = $facebook->api('me/feed', 'POST', array('message' => 'LOLs', 'access_token' => $page_access_token)); 
            }
        }
     }
     else { 
        //if user is not logged in, make them log in.
        header('location:' . $facebook->getLoginURL(array('scope' => 'publish_stream, manage_pages')));
     }