0

索引.php

     require_once ('../src/facebook.php');
     $facebook = new Facebook(array(
     'appId' => 'xxxxxxxxxxxx',
    'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    'cookie' => true,
    ));
    $session = $facebook->getSession();
    if (!empty($session)) {
try {
    $uid = $facebook->getUser();
    $user = $facebook->api('/me');
    echo 'session found';
        } catch (Exception $e) {}
    if(!empty($user)) {
        include 'result.php';
                }

            else {
                    $url = $facebook->GetLoginUrl(array('canvas' => 1,
                                   'fbconnect' => 0,
                                   'req_perms' => 'publish_stream, email, user_birthday, user_hometown, user_location, user_religion_politics, user_relationships, friends_about_me, friends_relationships',
                                   'next' => 'http://www.applicationsite.com/index.php',
                                   'cancel_url' => $appCanvasPage ));
                  #echo 'no user -> link to login';
    echo '<a href="'.$url.'">Click here to install the app</a>;
        }
    }
    else {
            $url = $facebook->GetLoginUrl(array('canvas' => 1,
                                   'fbconnect' => 0,
                                   'req_perms' => 'publish_stream, email, user_birthday, user_hometown, user_location, user_religion_politics, user_relationships, friends_about_me, friends_relationships',
                                   'next' =>'http://www.applicationsite.com/index.php',
                                   'cancel_url' => $appCanvasPage ));
   #echo 'no session -> link to login';
    echo '<a href="'.$url.'">Click here to install the app</a>;
           }
       ?>

选择.php

    just to html links to :

    http://www.applicationsite.com/index.php?&param=1
    http://www.applicationsite.com/index.php?&param=1

结果.php

        <?php 


        extract($_GET);

        if (isset($param)){

        I show my result

        }
        else
        {
        include 'choice.php';   
        }

    ?>

当我第一次启动页面时,我得到“无会话”链接,所以我点击并要求我提供权限,一旦我点击“允许”,它会将我重定向到“choice.php”页面,这意味着 $参数未设置。那太棒了。

但是当我点击它时,我会回到带有“no session”链接的索引页面,我必须再次点击该链接,然后它会让我回到“choice.php”页面。我不断转身。

4

1 回答 1

0

检查这个...我将 if !empty(user) 移到页面底部并使用 if $user... 如果这不起作用,那么我将放弃 ^^

     require_once ('../src/facebook.php');
     $facebook = new Facebook(array(
     'appId' => 'xxxxxxxxxxxx',
    'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    'cookie' => true,
    ));
    $session = $facebook->getSession();
    if (!empty($session)) {
try {
    $uid = $facebook->getUser();
    $user = $facebook->api('/me');
    echo 'session found';
        } catch (Exception $e) {}
    }
    else {
            $url = $facebook->GetLoginUrl(array('canvas' => 1,
                                   'fbconnect' => 0,
                                   'req_perms' => 'publish_stream, email, user_birthday, user_hometown, user_location, user_religion_politics, user_relationships, friends_about_me, friends_relationships',
                                   'next' =>'http://www.applicationsite.com/index.php',
                                   'cancel_url' => $appCanvasPage ));
   #echo 'no session -> link to login';
    echo '<a href="'.$url.'">Click here to install the app</a>';
           }
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
    <meta charset="UTF-8"/>
<meta name="description" content="" /> <meta name="keywords" content="" /> <meta name="author" content="" /> <title>test</title> <link rel="stylesheet" href="../styles.css" type="text/css" media="screen" /> </head> <body> <div id="fb-root"></div> <?php if ($user){ ?>
<!-- whatever you want to put on the website just for user goes here--> <div class="whatever"> <?php include "result.php";?> </div> <?php } ?> </body> </html>

于 2011-05-06T13:14:54.260 回答