Linwe
Linwe

Reputation: 325

Facebook application : Doesn't redirect to OAuth in an iFrame

I am currently developing a facebook application using the php sdk and the js sdk. (I need both of them)

When a user has not yet authorized the application and loads the canvas page (https://apps.facebook.com/app_name/), nothing happens, he just gets a blank page with the facebook bar on top. But if he loads the direct url of the application (https://my_app.mydomain.com), it works fine and he is redirected to the OAuth Dialog. If he authorizes the application, he is then redirected to https://apps.facebook.com/app_name/ and the iframe loads correctly.

If the user has already authorized the applications, both links are working (https://apps.facebook.com/app_name/ and https://my_app.mydomain.com).

Here is my authentication code :

<?php

require 'php-sdk/facebook.php';

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

$user = $facebook->getUser();



if ($user) {
  try {
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    $user = null;
  }
}

if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {

    $params = array(
      'scope' => 'publish_stream',
      'redirect_uri' => 'https://apps.facebook.com/quiet_quies/'
    );

  $loginUrl = $facebook->getLoginUrl($params);
  header('Location: ' . $loginUrl);
}

Does anybody have an idea about this ? It's really driving me mad... Thanks for you help.

Upvotes: 1

Views: 1466

Answers (1)

Smita
Smita

Reputation: 4634

yes, @CBroe is right, in your php code try replacing header('Location: ' . $loginUrl); line with

echo "<script language=javascript>top.location.href ='".$loginUrl."'</script>";

it should work then.

Upvotes: 3

Related Questions