Reputation: 1697
is it possible to get an valid access token for an user via a cronjob? i want to create an app that parse every night all posts from the user and check if there are some special chars.
with the app access key i have only access to the public posts from the user.. with the user access token i can access also private posts
but the user access token expires
is it possible to refresh the user token with an cronjob? that means the cronjob may have to refresh 100 user access tokens and i dont have the user du open the authorization dialog because its called on a server via cronjob
I'am using php for the facebook api
Upvotes: 0
Views: 2420
Reputation: 11
If you use the facebook jdk you can use: $token = $facebook->getAccessToken();
then, save $token
into database for use by cronjob
$args = array(
'access_token' => $page_info['access_token'], //Offline Access Token From Database
'message' => $_POST['description'],
'link' =>$_POST['link'],
'picture' =>$_POST['image'],
'name' =>$_POST['title']
);
$post_id = $facebook->api("/$page_id/feed","post",$args);
with $page_id
is id of fanpage or
$post_id = $facebook->api("/me/feed","post",$args);
Upvotes: 1
Reputation: 164467
No, this is not possible, it even say that explicitly in the official Removal of offline_access Permission post:
The user must access your application before you're able to get a valid "authorization code" to be able to make the server-side OAuth call again. Apps will not be able to setup a background/cron job that tries to automatically extend the expiration time, because the "authorization code" is short-lived and will have expired.
With that said, when you get an access token from a Server-Side authentication flow, the token you get should last for a month, if you persist it then you can then use it for that month.
After that month is over, and if the user hasn't re-engaged your app then the access token will be expired and you'll have to pass on that user.
Upvotes: 1