Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
I keep finding that after a few days I'm no longer able to post to Facebook from what I'm assuming is due to the access token expiring. This isn't very practical as you don't know there's a issue until you add a node, and I'm also not always about to re-login
I have found that there is a way to apparently get a long lived 60 day token using the following $fb->setExtendedAccessToken();
so I've added it like below but guess I won't know for a while as to weather it has worked or now.
function fb_autopost_facebook_login() {
// Show error messages from Facebook.
if (isset($_GET['error'])) {
drupal_set_message(t('An error happened while connecting with Facebook. Reason: %reason. Description: %description', array('%reason' => $_GET['error_reason'], '%description' => $_GET['error_description'])), 'error');
}
else {
try {
$fb = new FBAutopost();
if ($fb_user = $fb->getUser()) {
$fb->setExtendedAccessToken();
$token = $fb->getAccessToken();
variable_set('fb_autopost_token', $token);
$user_profile = $fb->api('/me?fields=id');
variable_set('fb_autopost_account_id', $user_profile['id']);
}
}
catch (FacebookApiException $e) {
// Do nothing with the exception.
drupal_set_message($e->getMessage(), 'error');
}
}
drupal_goto('admin/config/services/fbautopost');
}
Comment | File | Size | Author |
---|---|---|---|
#1 | Access_Token_Debugger_-_Facebook_Developers.png | 157.6 KB | e0ipso |
Comments
Comment #1
e0ipsoIt's been a long time since I dealt with this, but I see this when debugging my access token (which I got by typing
drush vget --exact fb_autopost_token
)Comment #2
e0ipsoComment #3
WebWalker3D CreditAttribution: WebWalker3D commentedI have run into this issue as well. According to Facebook:
source: https://developers.facebook.com/docs/php/FacebookSession/5.0.0
If this is the case, why are long lived access tokens not being issued to users of Facebook Autopost?
Access tokens were also explained as automatically refreshing when they are used. e.g. If I have a long-lived session (which is at least 60 days) and I use it tomorrow, that 60 days restarts. In other words, my access token should never expire.
source: https://developers.facebook.com/docs/facebook-login/access-tokens/expira...
Some insight would be helpful. I believe the related issue is also questioning this.
Comment #4
WebWalker3D CreditAttribution: WebWalker3D commentedComment #5
arsn CreditAttribution: arsn commentedHello,
@marcus178 I had the same issue and thought I would solve it the same way you suggested it until I applied the proper permissions under
admin/config/services/fbpermissions
and connected once more.Then thanks to @e0ipso test #2138415#comment-8300507 I could check that my Token is now unlimited and it seems to work.
Enables your application to retrieve access_tokens for Pages and Applications that the user administrates. The access tokens can be queried by calling /{user_id}/accounts via the Graph API. See here for generating long-lived Page access tokens that do not expire after 60 days.
Hope this help. If you had the same issue and solve it this way, we may close this issue as the module works as designed when properly configured.