You are here

function google_analytics_reports_oauth_callback in Google Analytics Reports 7

Same name and namespace in other branches
  1. 6 google_analytics_api.pages.inc \google_analytics_reports_oauth_callback()

Page callback - Provided for Google to call back during the OAuth process.

1 string reference to 'google_analytics_reports_oauth_callback'
google_analytics_api_menu in ./google_analytics_api.module
Implementation of hook_menu().

File

./google_analytics_api.pages.inc, line 150
Admin and OAuth callbacks.

Code

function google_analytics_reports_oauth_callback() {
  $key = variable_get('google_analytics_reports_consumer_key', 'anonymous');
  $secret = variable_get('google_analytics_reports_consumer_secret', 'anonymous');
  $session_data = $_SESSION['google_analytics_reports_oauth'];
  unset($_SESSION['google_analytics_reports_oauth']);
  $token = $session_data['token'];
  if (!is_array($token) || !$key || !$secret) {
    drupal_set_message(t('Invalid Google Analytics OAuth request'), 'error');
    return ' ';
  }
  if ($token['oauth_token'] != $_GET['oauth_token']) {
    drupal_set_message(t('Invalid OAuth token.'), 'error');
    return ' ';
  }
  module_load_include('inc', 'google_analytics_api', 'GAFeed.lib');
  $GAFeed = new GAFeed($key, $secret, $token['oauth_token'], $token['oauth_token_secret']);

  /* Google required the verifier */
  $GAFeed
    ->setVerifier($_GET['oauth_verifier']);
  $response = $GAFeed
    ->getAccessToken();
  variable_set('google_analytics_reports_oauth_token', $response['oauth_token']);
  variable_set('google_analytics_reports_oauth_token_secret', $response['oauth_token_secret']);
  drupal_goto('admin/config/system/google-analytics-reports');
}