2012-08-11 3 views
0

나는 페이스 북에 응용 프로그램을 가지고 있으며, pagetabs 만 사용하고 있습니다. 모든 것이 제대로되고 있습니다. 내가 좋아하는, 응용 프로그램을 허용 요청 권한을 허용하지만, 지금은 페이지로 돌아오고 오류가있다, 그것은 계속해서 다시로드 ... 브라우저는 항상 그것을 다시로드하기 때문에 페이지를로드 할 수 없습니다, 나도 몰라 ... 그것을 해결하는 방법oauth facebook in page tab reloads

정말 감사합니다 여기에

내 코드입니다 : 누군가가 당신의 스크립트가 일을 항상 하는 팬

<?php 

require_once "sdk/facebook.php"; 

$app_id = "MY_APPID"; 
$app_secret = "MY_SECRET"; 

$is_fan = false; 

// Init facebook api. 
$facebook = new Facebook(array(
    'appId' => $app_id, 
    'secret' => $app_secret, 
    'cookie' => true 
)); 

// Get and decode signed request. 
$signed_request = $facebook->getSignedRequest(); 
if (isset($_REQUEST['signed_request'])) { 
    $encoded_sig = null; 
    $payload = null; 
    list($encoded_sig, $payload) = explode(
     '.', $_REQUEST['signed_request'], 2 
    ); 
    $sig = base64_decode(strtr($encoded_sig, '-_', '+/')); 
    $data = json_decode(
     base64_decode(strtr($payload, '-_', '+/'), true) 
    ); 
    $signed_request = $data; 
} 
else { 
    $signed_request = false; 
} 

// Determine if we have a fan request. 
if($signed_request) { 
    if($signed_request->page->liked) { 
     $is_fan = true; 
    } 
} 

// for fans 
if ($is_fan) { ?> 

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <link href="css/style.css" rel="stylesheet" type="text/css" />  

    <script> 
     var oauth_url = 'https://www.facebook.com/dialog/oauth/'; 
     oauth_url += '?client_id=414328901957674'; 
     oauth_url += '&redirect_uri=' + encodeURIComponent('https://www.facebook.com/pages/null/167838393340757/?sk=app_414328901957674'); 
     oauth_url += '&scope=user_birthday,user_likes,photo_upload,publish_stream,user_about_me,user_photos,user_hometown,user_location' 

     window.top.location = oauth_url; 
    </script> 

    </head> 
    <body background="images/fanda.jpg" style="overflow:hidden;""> 
     </body> 

<?php } 

// for non-fans 
else { ?> 

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <link href="css/style.css" rel="stylesheet" type="text/css" />  
    </head> 
    <body background="images/klikni-like.jpg" style="overflow:hidden;"> 
    </body> 

<?php } ?> 

답변

0

입니다 :

window.top.location = oauth_url; 

누군가 팬인 경우 페이지가 무한대로 다시로드됩니다.

0

문제점에 대한 해결책을 찾았습니다. ($ is_fan)을 확인하면 다음과 같이 업데이트됩니다.

$user_id = $facebook->getUser(); 
if ($is_fan) { 
     if($user_id) 
      { 
       code after authentication and page Liked 
      } 

      } 
else { 
      <script> 
       var oauth_url = 'https://www.facebook.com/dialog/oauth/'; 
       ................ Next 4 lines same as the above code .............. 
      </script> 
     }