Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将manage_pages权限设置为特定facebook页面?_Php_Facebook Graph Api - Fatal编程技术网

Php 如何将manage_pages权限设置为特定facebook页面?

Php 如何将manage_pages权限设置为特定facebook页面?,php,facebook-graph-api,Php,Facebook Graph Api,如何将应用程序的“管理页面”权限仅设置为特定页面。现在我的应用程序获得了管理fb用户所有页面的权限。。我如何限制此操作并获得仅访问特定页面的权限 我使用的是一种简单的身份验证方法 $app_id = 'xxxxxxxxxxxxx'; $app_secret = 'xxxxxxxxxxxxxxxx'; $my_url = 'http://xxxxxxxxxxx.com/xxxx/facebook?client=params'; $code = $_REQUEST["

如何将应用程序的“管理页面”权限仅设置为特定页面。现在我的应用程序获得了管理fb用户所有页面的权限。。我如何限制此操作并获得仅访问特定页面的权限

我使用的是一种简单的身份验证方法

$app_id     = 'xxxxxxxxxxxxx';
$app_secret = 'xxxxxxxxxxxxxxxx';
$my_url     = 'http://xxxxxxxxxxx.com/xxxx/facebook?client=params';

$code        = $_REQUEST["code"];

//auth user
if(empty($code)) {
$dialog_url = 'https://www.facebook.com/dialog/oauth?client_id=' 
                . $app_id . '&redirect_uri=' . urlencode($my_url).'&scope=offline_access,read_stream,publish_stream,manage_pages';
                echo("<script>top.location.href='" . $dialog_url . "'</script>");
            }

//get user access_token
$token_url = 'https://graph.facebook.com/oauth/access_token?client_id='
            . $app_id . '&redirect_uri=' . urlencode($my_url) 
            . '&client_secret=' . $app_secret 
            . '&code=' . $code;
$access_token = file_get_contents($token_url);


am using the above code for authentication. when i try to print the $_REQUEST params, i couldnt find any variable names 'signed_request'.  is any other method can we use with the above code..??
$app_id='xxxxxxxxxxxx';
$app_secret='xxxxxxxxxxxxxxxxxx';
$my_url=http://xxxxxxxxxxx.com/xxxx/facebook?client=params';
$code=$_请求[“code”];
//授权用户
if(空($code)){
$dialog\u url='1https://www.facebook.com/dialog/oauth?client_id=' 
.$app\u id.&redirect\u uri='.urlencode($my\u url)。'&scope=offline\u访问、读取\u流、发布\u流、管理\u页面';
echo(“top.location.href=”。$dialog\u url。””;
}
//获取用户访问令牌
$token\u url='1https://graph.facebook.com/oauth/access_token?client_id='
. $应用程序id。”&重定向_uri='。urlencode($my_url)
. '&客户机_secret='$app_秘密
. '&代码='$代码;
$access\u token=file\u get\u contents($token\u url);
我使用上述代码进行身份验证。当我试图打印$\u请求参数时,我找不到任何变量名“signed\u REQUEST”。以上代码是否可以使用任何其他方法。。??

不幸的是,这是不可能的。很烦人,但是。。这是facebook,所以没有什么可期待的。

你应该站在自己的角度来做这件事。Facebook将在签名请求中向您发送页面id,以便您可以验证页面并显示/禁用内容:

<?php
if(!empty($_REQUEST["signed_request"])) {
    $app_secret = "APP_SECRET";
    $data = parse_signed_request($_REQUEST["signed_request"], $app_secret);

    if (isset($data["page"])) {
        echo $data["page"]["id"];
    } else {
        echo "Not in a page";
    }
}

function parse_signed_request($signed_request, $secret) {
    list($encoded_sig, $payload) = explode('.', $signed_request, 2); 

    // decode the data
    $sig = base64_url_decode($encoded_sig);
    $data = json_decode(base64_url_decode($payload), true);

    if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
        error_log('Unknown algorithm. Expected HMAC-SHA256');
        return null;
    }

    // check sig
    $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
    if ($sig !== $expected_sig) {
        error_log('Bad Signed JSON signature!');
        return null;
    }

    return $data;
}

function base64_url_decode($input) {
    return base64_decode(strtr($input, '-_', '+/'));
}