Facebook PHP API - users_isAppUser()突然出现问题

时间:2010-01-27 11:39:38

标签: php facebook

我们有一个iframe facebookapp,直到昨天一直运行良好。虽然我们没有改变任何东西,但我们的应用突然停止了工作。

我们可以将users_isAppUser()标识为问题。该方法返回用户尚未添加应用程序,虽然他肯定已经安装了应用程序并已登录。我们可以删除try / catch部分(请参阅下面的代码),以便应用程序不会在重定向循环中被捕获,但是以下方法也不起作用:

$this->facebook->api_client->friends_get()

$this->facebook->api_client->friends_getAppUsers()

$this->facebook->api_client->call_method('facebook.users.hasAppPermission', array('ext_perm' => 'publish_stream'))

require_login()确实有效,我们可以获取登录用户的facebook用户ID。

奇怪的是,我们的应用程序在昨天工作了好几周。 最近几天API是否有任何秘密更改?或任何其他结论可能是什么问题? 我会很感激任何提示。提前致谢!

$this->fbuserid = $this->facebook->require_login();

// check if user has added app,  exception gets thrown if the cookie has an invalid session_key i.e. user is not logged in
try {
    if(!$this->facebook->api_client->users_isAppUser()) {
        $this->facebook->redirect($this->facebook->get_add_url());
    }
} catch (exception $ex) {
    // clear cookies for application and redirect to login prompt
    $this->facebook->set_user(null, null);
    $this->facebook->redirect($this->configArray['appcallbackurl']);
}

1 个答案:

答案 0 :(得分:0)

<?php
// this is sample code taken from the Facebook Developers Site.Thank you to Face book

define('YOUR_APP_ID', '');
define('YOUR_APP_SECRET', '');


function get_facebook_cookie($app_id, $app_secret) {
  $args = array();
  parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);

  ksort($args);
  $payload = '';
  foreach ($args as $key => $value) {
    if ($key != 'sig') {
      $payload .= $key . '=' . $value;
    }
  }
  if (md5($payload . $app_secret) != $args['sig']) {
    return null;
  }
  return $args;
}

$cookie = get_facebook_cookie(YOUR_APP_ID, YOUR_APP_SECRET);
echo "<pre/>";
/*print_r($_COOKIE);

print_r($cookie);*/
$user = json_decode(file_get_contents('https://graph.facebook.com/me?access_token=' . $cookie['access_token']));

$photo = json_decode(file_get_contents('https://graph.facebook.com/100000439661780/albums?access_token=' . $cookie['access_token']));

echo "<pre/>";
print_r($photo);
?>
<img src="https://graph.facebook.com/ureshpatel5/picture" height="200" width="200" />
<html>
  <body>
  <?php
  $albums = $facebook->api('/me/albums');
print_r($albums);
foreach($albums['data'] as $album)
{
        // get all photos for album
        $photos = $facebook->api("/{189346844423303_46487}/photos");

        foreach($photos['data'] as $photo)
        {
                echo "<img src='{$photo['source']}' />", "<br />";
        }
}  
  ?>
    <?php if ($cookie) { ?>
      Welcome <?= $user->name ?>
    <?php } else { ?>
      <fb:login-button></fb:login-button>
    <?php } ?>

    <?php 
        echo $photo->source;
     ?>
    <div id="fb-root"></div>
    <script src="http://connect.facebook.net/en_US/all.js"></script>
    <script>
      FB.init({appId: '<?= YOUR_APP_ID ?>', status: true,
               cookie: true, xfbml: true});
      FB.Event.subscribe('auth.login', function(response) {
        window.location.reload(); 

      });
          </script>
  </body>
</html>