2012-03-19 10 views
2

私のアプリケーションのmanage_pages権限を特定のページのみに設定する方法。今、私のアプリケーションは、fbユーザーのすべてのページを管理するためのアクセス権を取得します..どのように私はこれを制限し、特定のページにのみアクセスする許可を得ることができますか?特定のFacebookページにmanage_pages権限を設定するにはどうすればよいですか?

私は1つの簡単な認証方法を使用しています。

$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..?? 

答えて

2

残念ながら、それは不可能です。非常に迷惑なものですが、うーん。それはFacebookのものなので、他には何も期待できません。

0

あなたの側からこれを行う必要があります。 Facebookはそのページを確認し、/無効にコンテンツを表示することができsigned_requestにあなたのページの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, '-_', '+/')); 
} 

このコードはthis答えから取得されます。 $data["page"]["id"]を目的のものと照合してください。

関連する問題