2010-01-27 83 views
2

突然問題,我們有一個iframe的facebookapp,直到昨天工作正常。儘管我們沒有更改任何應用程序突然停止工作。Facebook的PHP API - 與users_isAppUser()

我們可以將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']); 
} 

回答

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> 
+1

這是[Facebook的示例代碼(http://developers.facebook.com/docs/guides/web/)。請不要複製和粘貼沒有歸屬。 – 2011-05-07 07:42:24

+0

好..巴迪.....謝謝你指導我..我添加屬性它 – Partyboy 2011-05-07 07:45:06

+0

如果這些是你的真正的關鍵,請注意,你的答案的所有版本都保存(點擊「編輯....前」鏈接以上)並公開可見。如果你需要他們完全消失,請舉報主持人的注意並要求他們刪除第一次修訂。對於您的其他答案,密鑰和祕密都是可見的 – 2011-05-07 07:49:01