I created a Facebook page, added a new Tab with an application.
Now I want todo these steps:
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?
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.