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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。