开发者

How to set age restriction using the new PHP lib?

开发者 https://www.devze.com 2023-04-05 02:15 出处:网络
My old method to set age restriction is like $userID = $facebook->require_login($required_permissions = \'email, publish_stream,offline_access\');

My old method to set age restriction is like

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

while the old method to be deprecated soon, I have to rewrite the code. I tried all means, then find I should call the api method this way,

$accessToken=$facebook->getAccessToken();
echo "<BR>access_token is: ".$accessToken;
$result = $facebook->api(array(
      'method' => 'admin.setRestrictionInfo',
      'restriction_str' => json_encode(array('age开发者_如何学JAVA' => '18+')),
      "access_token" => $accessToken,
));

However, it always throw the following error

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

Any solution? Thanks for your help.


I have been struggling with this for a while and finally figured it out so I thought I'd throw the answer out there for you.

That getAccessToken thing is whack. Apparently that's just what token is being used by the SDK and not necessarily your app's token.

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

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

Obviously set the $app_id and $app_secret to yours. The structure for an app's access token is [app id]|[app secret].

The structure for the URL call is:

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

Hope this helps!!!

0

精彩评论

暂无评论...
验证码 换一张
取 消