2011-09-16 43 views
0

我的老方法來設置年齡限制就像是如何使用新的PHP庫設置年齡限制?

$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 

任何解決方案?謝謝你的幫助。

回答

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} 

希望這有助於!