开发者

Facebook canvas application - php Auth issues

开发者 https://www.devze.com 2023-01-02 21:36 出处:网络
I am in the process of devloping a facebook canvas application in php and FBML, and am having issues when it comes to setting up authorization for the application. I basicly do not kno how to go about

I am in the process of devloping a facebook canvas application in php and FBML, and am having issues when it comes to setting up authorization for the application. I basicly do not kno how to go about it, or what the best method is.

I have been searching around on the internet most of the day but either stummble on old API things, or i dont know how to implement what they are explaining.

Here is what i have:

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

$session = $facebook->getSession();

$fbme = null;
if ($session) {
  try {
    $uid = $facebook->getUser();
    $fbme = $facebook->api('/me');
  } catch (FacebookApiException $e) {
      d($e);
  }
}

if (!$fbme) {
  $loginUrl = $facebook->getLoginUrl(array(
               'canvas' => 1,
               'fbconnect' => 0,
        'req_perms' => "publish_stream,user_birthday,friends_birthday,user_events,user_hometown,friends_hometown,user_location,friends_location,offline_access,"
           ));;
}

if (isset($loginUrl))开发者_Python百科 {
    echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
    exit;
}

But that does nothing, and if i try with changing the headers instead of using script block, i get:

The URL ... is not valid

Am i going about this all wrong?

Thanks in advance for any help.

Andy


My common include has the following for authenticating:

$facebook = new Facebook(array(
    'appId'  => $ini['appid'],
    'secret' => $ini['appsecret'],
    'cookie' => true,
));

$session = $facebook->getSession();
$fbme = null;
if ($session) {
    try {
        $fbme = $facebook->api('/me');
    }
    catch (FacebookApiException $e) {
        error_log($e);
    }
}

// new login check
if (!$fbme) {
    $loginUrl = $facebook->getLoginUrl(array(
        'canvas' => 1,
        'fbconnect' => 0,
        'req_perms' => 'email',
        'next' => FB_APP_URL,
        'cancel_url' => FB_APP_URL,
    ));
    echo '<fb:redirect url="' . $loginUrl . '" />';
}

That basically shows a message prompting the using the either add the application or leave; if they are already authenticated then just proceeds with what's beyong the if (!$fbme) block.

0

精彩评论

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

关注公众号