开发者

Facebook Authentication window does not display?

I have a file named fbmain.php which do Authentication part of my facebook app.

But it doesn't display the Authentication window?

//fbmain.php

<?php
    //facebook application
    //set facebook application id, secret key and api key here
    $fbconfig['appid' ] = "MY_APP_ID";  
    $fbconfig['secret'] = "MY_APP_SECRET";   

    $uid            =   null; //facebook user id

    try{
        include_once "facebook.php";
    }catch(Exception $o){
        echo '<pre>';
        print_r($o);
        echo '</pre>';
    }
    // Create our Application instance.
    $facebook = new Facebook(array(
      'appId'  => $fbconfig['appid'],
      'secret' => $fbconfig['secret'],
      'cookie' => true,
    ));

    //Facebook Authentication part
    $session = $facebook->getSession();

    $loginUrl = $facebook->g开发者_如何学运维etLoginUrl(
            array(
            'canvas'    => 1,
            'fbconnect' => 0,
            'req_perms' => 'email,publish_stream,status_update,user_birthday,user_location,user_work_history,user_likes,user_photos'
            )
    );

    if (!$session) {
        echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
        exit;
    } 
    if ($session) {
    echo "<br/>session ok";   //It create a session and disply 'session ok' string
        try {
            $uid      =   $facebook->getUser(); 
        } catch (FacebookApiException $e) {
            echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
            exit;
        }       
    }

?>

Can anyone please help me with this?


Which version of PHP-SDK you are using??

I think you can get rid of getSession() and use just getUser().

change your code as below and try again..

$uid      =   $facebook->getUser(); 

if ($uid) {
 // do some api calls or something else
}
else 
{
   echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
}       

else in index.php just include your fbmain.php and use a image button where you can link the $loginurl..

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜