0

我开发了一个 Facebook 应用程序并使用 PHP-sdk 我使用官方文档中描述的算法来允许用户加入我的应用程序,然后我将他/她的 user_id 存储在数据库中。我的应用程序使用 publish_stream 权限,因此它会自动将帖子发布到用户的时间线。

我发现该应用程序始终无法为数据库中的某些注册用户(不是全部)发布帖子。我考虑到这一点,因为他们可能会在批准所需权限之前将其注册到数据库中。以下是我在 Facebook api 官方文档中使用的代码的蓝图:

<?php  
  require_once('php-sdk/facebook.php');
  $config = array(
    'appId' => 'YOUR_APP_ID',
    'secret' => 'YOUR_APP_SECRET',
  );
  $facebook = new Facebook($config);
  $user_id = $facebook->getUser();
?>
<html>
  <head></head>
  <body>

  <?php
    if($user_id) {
      try {
       /* $user_profile = $facebook->api('/me','GET');
        echo "Name: " . $user_profile['name'];*/
     //Here I run the code to save.
         saveTheUserIdToRecordInTheDB($user_id);
       //hypothetical function to save

      } 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(); 
        echo 'Please <a href="' . $login_url . '">login.</a>';
        error_log($e->getType());
        error_log($e->getMessage());
      }   
    } else {

      // No user, print a link for the user to login
      $login_url = $facebook->getLoginUrl();
      echo 'Please <a href="' . $login_url . '">login.</a>';

    }

  ?>

  </body>
</html> 

我的主要问题是:如果用户点击了登录链接,然后他/她由于任何原因没有继续(失去互联网连接,拒绝授予应用程序权限等),是否有可能实现假设功能saveTheUserIdToRecordInTheDB()运行并将该用户的 Facebook ID 保存到数据库?

或者有些用户无法发布帖子的解释是什么?

4

0 回答 0