如何发布一个帖子给我所有的应用程序用户


How to publish a post to all my app users?

我正试图发布到我所有的应用程序用户墙,我使用这段代码只发送给一个用户:==>>

这段代码只发布在一个墙上

 <?
  $config = array(
    'appId' => 'xxxxxxxxxxxxxxxxxx',
    'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxx',
  );
  $facebook = new Facebook($config);
  $user_id = $facebook->getUser();
?>
<html>
  <head></head>
  <body>
  <?
    if($user_id) {
      // We have a user ID, so probably a logged in user.
      // If not, we'll get an exception, which we handle below.
      try {
        $ret_obj = $facebook->api('/me/feed', 'POST',
                                    array(
                                      'link' => 'www.example.com',
                                      'message' => 'Posting with the PHP SDK!'
                                 ));
        echo '<pre>Post ID: ' . $ret_obj['id'] . '</pre>';
      } catch(FacebookApiException $e) {
        // If the user is logged out, you can have a 
        // user ID even though the access token is invalid.
        // In this case, we'll get an exception, so we'll
        // just ask the user to login again here.
        $login_url = $facebook->getLoginUrl( array(
                       'scope' => 'publish_stream'
                       )); 
        echo 'Please <a href="' . $login_url . '">login.</a>';
        error_log($e->getType());
        error_log($e->getMessage());
      }   
      // Give the user a logout link 
      echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';
    } else {
      // No user, so print a link for the user to login
      // To post to a user's wall, we need publish_stream permission
      // We'll use the current URL as the redirect_uri, so we don't
      // need to specify it here.
      $login_url = $facebook->getLoginUrl( array( 'scope' => 'publish_stream' ) );
      echo 'Please <a href="' . $login_url . '">login.</a>';
    } 
  ?>      
  </body> 
</html>  

如何发布一个帖子给我所有的应用程序用户?!!

请指教!

谢谢

  1. 获取所有应用程序用户-

    使用FQL,只需执行:

    $fql="SELECT uid FROM user
    WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = ".$me['id'].")
    AND is_app_user = 1";
    
  2. 遍历每个用户并使用feed