如何使用新的 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
有解决方案吗?感谢您的帮助。
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.
我已经为此苦苦挣扎了一段时间,终于弄清楚了,所以我想我应该为你提供答案。
getAccessToken
的事情很糟糕。显然,这只是 SDK 使用的令牌,而不一定是您应用程序的令牌。显然将
$app_id
和$app_secret
设置为您的。应用程序访问令牌的结构为[应用程序 ID]|[应用程序密钥]
。URL 调用的结构是:
希望这有帮助!
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.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:
Hope this helps!!!