doujian1954 2012-08-07 12:58
浏览 28
已采纳

Facebook页面标签 - 应用程序

I created a Facebook page, added a new Tab with an application.

Now I want todo these steps:

  1. See if User liked the page // Is Working
  2. Ask for permissions to post a status // Isn't working
  3. Finish.

This is the code which I use:

$permissions = array (
    'email',
    'user_status',
    'publish_stream',
    'status_update'
);

public function __construct($app_id, $secret, $perm)
{

        $this->facebook = new Facebook(array(
            'appId'  => $app_id,
            'secret' => $secret,
            'cookie' => true
        ));
        $this->perm = $perm;
}


        public function checkPermissions()
        {
            $allPerm = true;
            $permissions = $this->facebook->api("/me/permissions");
            foreach($this->perm as $value)
            {
                if(!array_key_exists($value, $permissions['data'][0]) ) {
                    $allPerm = false;
                }
            }
            return $allPerm;
        }

        public function RequestPermissions()
        {
            header( "Location: " . $this->facebook->getLoginUrl($this->GenerateScope()) );
        }

    public function GenerateScope()
    {
        $scope = null;
        $last_key = array_keys($this->perm);
        $last_key = end($last_key);
        foreach ($this->perm as $key => $value) {
            if ($key == $last_key) {
                $scope .= $value;
            } else {
                $scope .= $value . ',';
            }
        }
        return array("scope" => $scope);
    }

So, I check for the Permissions, if not all are set, I want to ask for them. $this->facebook->getLoginUrl($this->GenerateScope()).

But when i display the link, or redirect to it, nothings (really nothing) happens?

  • 写回答

1条回答 默认 最新

  • matlabmann 2012-08-07 13:08
    关注

    Your tab application is operating within an iframe element on facebook.com. To redirect users to a different URL, you'll have to change the top most frame's location. This is possible using JavaScript, so all you have to do is get your PHP code to echo out this JavaScript code -

    $url = $facebook->getLoginUrl(...your_params...);
    
    echo "<script language=javascript>";
    echo "top.location.href ='".$url."';";
    echo "</script>";
    exit();
    

    That will execute the redirect for your users.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度