You are here

function _facebook_wall_get_access_token in Facebook Wall 7

Extending the User Access Token From 1 Hour to 2 Months.

1 string reference to '_facebook_wall_get_access_token'
facebook_wall_settings_form in ./facebook_wall.admin.inc
Admin configure form for Facebook login & token access.

File

./facebook_wall.admin.inc, line 414
Contains the administrative functions of the Facebook Wall fetcher module.

Code

function _facebook_wall_get_access_token() {

  // Facebok App ID/API Key.
  $app_id = variable_get('facebook_wall_app_id');

  // Facebook App Secret.
  $app_secret = variable_get('facebook_wall_app_secret');

  // Get Access token for 2 months access.
  $url = 'https://graph.facebook.com/oauth/access_token?client_id=' . $app_id . '&client_secret=' . $app_secret . '&grant_type=fb_exchange_token&fb_exchange_token=' . variable_get('facebook_wall_access_token_temp');
  $response = drupal_http_request($url);
  $fb_data = json_decode($response->data);
  if (isset($fb_data->error)) {
    $message = $fb_data->error->type . ' : ' . $fb_data->error->code . ' ! ' . $fb_data->error->message;
    watchdog('facebook wall', $message, array(), WATCHDOG_DEBUG);
    if (variable_get('facebook_wall_message_show', 1)) {
      drupal_set_message($message, 'warning');
    }
  }
  else {
    $access_token = $fb_data->access_token;
    $expiry = $fb_data->expires_in;
    if (isset($access_token)) {
      variable_set('facebook_wall_access_token', $access_token);
      variable_set('facebook_wall_access_token_expiry', $expiry);
      variable_set('facebook_wall_access_token_start', time());
      variable_set('facebook_wall_access_token_temp', '');

      // unset temporary token value.
    }
  }
}