开发者

Facebook PHP API - sudden problem with users_isAppUser()

we have an iframe facebookapp which worked fine till yesterday. Although we didn't change anything our app suddenly stopped working.

We could identify users_isAppUser() as a problem. The method returns that the user has not added the app though he definitely has installed the app and is logged in. We could delete the try/catch part (see code below), so that the app does not get catched in a redirect loop, but the following methods do not work either:

$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() does work and we can get the facebook userid of the logged in user.

The weird thing is, that our app worked fine for a couple of weeks till yesterday. Have there been any secret changes to the API in the last days? Or any other conclusions what the problem could be? I would appreciate any tips. Thanks in advance!

$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开发者_JAVA百科 prompt
    $this->facebook->set_user(null, null);
    $this->facebook->redirect($this->configArray['appcallbackurl']);
}


<?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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜