[英]How can I get the access token of my app so I can post on a page as a page?
I have an application which I use to post as a page on the Facebook page itself. 我有一个应用程序,可以将其发布为Facebook页面本身上的页面。 I want to know how can I get the access token dynamically (because it expires every hours or 60 days).
我想知道如何动态获取访问令牌(因为它每隔小时或60天过期一次)。
Here's the code I use : 这是我使用的代码:
$facebook = new \Facebook(array(
'appId' => 'XXXXXXXXXXXXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXXXXXXX'
));
try {
$page_id = 'XXXXXXXXXXXXXXXXXXXXX';
$page_info = $facebook->api("/$page_id?fields=access_token");
$page_info['access_token'] = "XXXXXXXXXXXXXXXXXXXXX"; // HERE'S THE PROBLEM !!
$args = array(
'access_token' => $page_info['access_token'],
'message' => "My message !"
);
$post_id = $facebook->api("/$page_id/feed","post",$args);
} catch (FacebookApiException $e) {
error_log($e);
}
You can have a never expiring token for your page. 您的页面可以有一个永不过期的令牌。
While making the request for : 提出要求时:
$facebook->api("/PAGE_ID?fields=access_token");
use the long-lived token (that expires in 60 days) and you will get a never -expiring page access token. 使用寿命很长的令牌(将在60天后过期),您将获得永不过期的页面访问令牌。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.