开发者

Facebook PHP API/App: iFrame

I have a simple App that used to work in the old API. It's an iFrame app and I can't get the user session with the new API no matter what I try. Here is the code I have now:

<?php
error_reporting(E开发者_运维问答_ALL);

require 'facebook.php';

$facebook = new Facebook(array(
  'appId'  => 'xxxx',
  'secret' => 'xxxx',
  'cookie' => true,
));

$session = $facebook->getSession();
if ( !$session )
{
 //echo "Failed. No session.<br />";

    $url = $facebook->getLoginUrl(array(
               'canvas' => 1,
               'fbconnect' => 0,
               'next'=>'http://www.facebook.com',
               'cancel_url' => 'http://www.facebook.com'
           ));

    //echo "<script type='text/javascript'>top.location.href = '$url';</script>";
    echo "<a href='".$url."' target='_blank'>First time using this App? Click here to connect it to your Facebook.</a>";

}
else {

    try {

        $uid = $facebook->getUser();
        $me = $facebook->api('/me');

        $updated = date("l, F j, Y", strtotime($me['updated_time']));

        echo "Hello " . $me['name'] . "<br />";
        echo "You last updated your profile on " . $updated;

    } catch (FacebookApiException $e) {

        echo "Error:" . print_r($e, true);

    }
}

No matter what I try, $session is never returned (after clicking the link). I am using the correct appID/secret/facebook.php but it always falls into the !$session if path. What am I doing wrong?


$facebook->getLogoutUrl();

This might help

https://github.com/facebook/php-sdk/tree/v3.1.1


The version of the PHP API that I am using that I downloaded a few days ago does not have $facebook->getSession()

So depending on the version you are using (assuming older versions had a getSession, I dont know I just started using the API) it may not have getSession anymore.

What the example that came with the api showed was using ->getUser to attempt to get a user object and checking if that was valid, then attempting to get the users profile via information to verify the connection is valid.

Hope that helps.

Jason Penick

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜