views:

291

answers:

2

Hi,

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)) {
    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

A: 

please enter the full Error Message. Is there a line e.g.28 or so that makes it easier for you/us to see where almost is your error?

max
+1  A: 

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.

Martin Bean
Hey martin, i am getting exception in $fbme = $facebook->api('/me'); I am using the latest php-sdk.
Webbisshh
What is the exception you are getting?
Martin Bean