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.

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

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件