douchan0523 2010-06-08 11:02
浏览 39
已采纳

Facebook画布应用程序 - php Auth问题

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

  • 写回答

1条回答 默认 最新

  • dongmeba4877 2010-07-12 13:56
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。