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

发布于 12-05 01:51 字数 979 浏览 0 评论 0原文

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

$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

有解决方案吗?感谢您的帮助。

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' => '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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠北森屋2024-12-12 01:51:40

我已经为此苦苦挣扎了一段时间,终于弄清楚了,所以我想我应该为你提供答案。

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 设置为您的。应用程序访问令牌的结构为[应用程序 ID]|[应用程序密钥]

URL 调用的结构是:

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

希望这有帮助!

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!!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文