重定向问题与最新版本的php-sdk

时间:2012-10-27 17:59:52

标签: facebook facebook-graph-api permissions publish facebook-authentication

我们使用了最新版本的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>';
    }
?>

我们允许应用程序(转到应用程序)并允许发布到墙上。

允许发布到墙后,它不会重定向应用程序URL($ appsurl)。它将显示如下

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

我们也在indexpage中尝试了重定向代码。

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

但重定向不会发生。

你能帮我吗?

1 个答案:

答案 0 :(得分:1)

试试这个:

$loginUrl   = $facebook->getLoginUrl(
            array(
                'scope'         => 'publish_stream',
                'redirect_uri'  => 'https://apps.facebook.com/yourNameSpace'
            )
    );