0

We have used latest version of php-sdk 3

<?php

    try{
        include_once "connect.php";
    }

    catch(Exception $o){
        echo '<pre>';
        print_r($o);
        echo '</pre>';
    }

   if (isset($_GET['code'])){
        header("Location: " . $appsurl);
        exit;
    }
    //~~

    //
    if (isset($_GET['request_ids'])){
        //user comes from invitation
        //track them if you need
    }

    $user            =   null; //facebook user uid
    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
    $uid       = $facebook->getUser();


    $loginUrl   = $facebook->getLoginUrl(
            array(
                'scope'         => 'publish_stream'
            )
    );

    if ($uid) {
      try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
      } catch (FacebookApiException $e) {
        //you should use error_log($e); instead of printing the info on browser
        d($e);  // d is a debug function defined at the end of this file
        $user = null;
      }
    }

    if (!$uid) {
        echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
        exit;
    }

    //get user basic description
    $userInfo           = $facebook->api("/$uid");

    function d($d){
        echo '<pre>';
        print_r($d);
        echo '</pre>';
    }
?>

we allow the application( Go to app) and allow post to wall.

After allowing post to wall it will not redirecting the application url($appsurl).It will display like this

https://[hostingurl]/?state=7f76eb2ad732398827215d86f946a690&code=AQBZ2nsbbs3lfBSBwr_HzFpcKIIZlfjAijl9db7wyn1xEIZ4-W7BqQbFtnVZ8UM_4nQ9qIk57msjw6RlLb6VQqGrF3nupBFoEmrypAPmftAsS4ILW9LEJA5gzTMb2VJhwBHHqSpwGHUbh98bNQQQxkX50Ns5kVaffUUylXrIgy6MQcLxU66hQS7qMImHg5Mi2tUrpPqlWbZNQzlooMkv1WAt#_=_

We tried the redirection code in indexpage also.

if (isset($_GET['code'])){
        header("Location: " . $appsurl);
        exit;
    }

but the redirection is not take place.

Could you please help me?

Arun Jose
  • 1
  • 1
  • possible duplicate of [how to set facebook return url](http://facebook.stackoverflow.com/questions/5167157/how-to-set-facebook-return-url) – ifaour Oct 27 '12 at 18:41

1 Answers1

1

try this:

$loginUrl   = $facebook->getLoginUrl(
            array(
                'scope'         => 'publish_stream',
                'redirect_uri'  => 'https://apps.facebook.com/yourNameSpace'
            )
    );
Smita
  • 4,634
  • 2
  • 25
  • 32