如何使用PHP在fb上发布?

时间:2014-07-21 20:09:00

标签: php facebook

我使用facebook apis在我的测试帐户上使用php发布。以下代码为我工作,它的工作原理。如果我使用我的帐户登录,我可以看到该帖子,但如果我使用其他帐户,则该帖子不会显示。我已将隐私设置修改为公开但仍然。我去了facebook的文档,但我找不到能解决问题的东西。谁能帮忙???

先谢谢

function fb_post($post, $msg, $url, $pic) {
  $temp_array = queryFBTable($post);
  if (count($temp_array) == 0) return;



// initialize Facebook class using your own Facebook App credentials
  // see: https://developers.facebook.com/docs/php/gettingstarted/#install
  $config = array();
  $config['appId'] = 'xxxxxxxxxxx';
  $config['secret'] = 'xxxxxxxxxxxxxxxx';
  $config['fileUpload'] = true; // optional
  $fb = new Facebook($config);

  // define your POST parameters (replace with your own values)
  // see: https://developers.facebook.com/docs/facebook-login/access-tokens/

  $params = array();
  if(isset($temp_array['AccessToken'])) {
    $params['access_token'] = $temp_array['AccessToken'];
  }
  if(isset($msg)) {
    $params['message'] = $msg;
  }
  if(isset($url)) {
    $params['link'] = $url;
  }
  if(isset($pic)) {
    $params['picture'] = $pic;
  }
    //"name" => "yooo",
    //"caption" => "www.pontikis.net",
    //"description" => "Automatically post on Facebook with PHP using Facebook PHP SDK. How to create a Facebook app. Obtain and extend Facebook access tokens. Cron automation."


  // post to Facebook
  // see: https://developers.facebook.com/docs/reference/php/facebook-api/
  try {
    //tim .. 1471145939793099
    // van .. 1491737127730006
    // mc .. 796523467054680
    $ret = $fb->api("/".$temp_array['userID']."/feed", 'POST', $params);
    echo "<br>Successfully posted to Facebook account ".$post.". <br/>";
  } 
  catch(Exception $e) {
    echo $e->getMessage();
  }
}

0 个答案:

没有答案