如何使用新的PHP lib设置年龄限制?

时间:2011-09-16 07:32:25

标签: php facebook-php-sdk

我设定年龄限制的旧方法就像

$userID = $facebook->require_login($required_permissions = 'email, publish_stream,offline_access');
$info = array('age' => '18+');
$success = $facebook->api_client->admin_setRestrictionInfo($info);

虽然很快就会弃用旧方法,但我必须重写代码。我尝试了所有方法,然后发现我应该这样调用api方法,

$accessToken=$facebook->getAccessToken();
echo "<BR>access_token is: ".$accessToken;
$result = $facebook->api(array(
      'method' => 'admin.setRestrictionInfo',
      'restriction_str' => json_encode(array('age' => '18+')),
      "access_token" => $accessToken,
));

但是,它总是抛出以下错误

access_token is: 112819402105453|9761b1a933b0277ff56453a6.1-1670893505|zJEVp2JXbHzRVSVXmJUgV-Fz13o
Fatal error: Uncaught Exception: 15: This method must be called with an app access_token. thrown in /usr/local/chroot/carrotbid/home/php/facebook_api/base_facebook.php on line 708

任何解决方案?谢谢你的帮助。

1 个答案:

答案 0 :(得分:2)

我一直在努力解决这个问题,终于想通了,所以我想我会把答案扔给你。

getAccessToken事情很糟糕。显然,这只是SDK使用的令牌,而不一定是您的应用程序的令牌。

$access_token = $app_id . "|" . $app_secret;

$facebook->api(array(
    "access_token"=>$access_token,
     "method"=>"admin.setRestrictionInfo",
     "restriction_str"=>"{'location':'CA'}"
));

显然,将$app_id$app_secret设置为您的。{应用访问令牌的结构为[app id]|[app secret]

URL调用的结构是:

https://api.facebook.com/method/admin.setRestrictionInfo?access_token=[APP_ID]|[APP_SECRET]&format=json&restriction_str={%22type%22:%22alcohol%22} 

希望这有帮助!!!