function authenticate()
 {
     if (isset($_REQUEST['ga_oauth_callback'])) {
         $o = get_option($this->optionname);
         if (isset($o['gawp_oauth']['oauth_token']) && $o['gawp_oauth']['oauth_token'] == $_REQUEST['oauth_token']) {
             $gdata = new WP_GData(array('scope' => 'https://www.google.com/analytics/feeds/', 'xoauth_displayname' => 'Google Analytics for WordPress by Yoast'), $o['gawp_oauth']['oauth_token'], $o['gawp_oauth']['oauth_token_secret']);
             $o['gawp_oauth']['access_token'] = $gdata->get_access_token($_REQUEST['oauth_verifier']);
             unset($o['gawp_oauth']['oauth_token']);
             unset($o['gawp_oauth']['oauth_token_secret']);
             $o['ga_token'] = $o['gawp_oauth']['access_token']['oauth_token'];
         }
         update_option($this->optionname, $o);
         wp_redirect(menu_page_url($this->hook, false));
         exit;
     }
     if (!empty($_GET['reauth'])) {
         $gdata = new WP_GData(array('scope' => 'https://www.google.com/analytics/feeds/', 'xoauth_displayname' => 'Google Analytics for WordPress by Yoast'));
         $oauth_callback = add_query_arg(array('ga_oauth_callback' => 1), menu_page_url('google-analytics-for-wordpress', false));
         $request_token = $gdata->get_request_token($oauth_callback);
         $options = get_option($this->optionname);
         unset($options['ga_token']);
         unset($options['gawp_oauth']['access_token']);
         $options['gawp_oauth']['oauth_token'] = $request_token['oauth_token'];
         $options['gawp_oauth']['oauth_token_secret'] = $request_token['oauth_token_secret'];
         update_option($this->optionname, $options);
         wp_redirect($gdata->get_authorize_url($request_token));
         exit;
     }
 }
 /**
  * Checks if there is a callback or reauth to get token from Google Analytics api
  */
 private function connect_with_google_analytics()
 {
     $option_name = 'yst_ga_api';
     if (isset($_REQUEST['ga_oauth_callback'])) {
         $o = get_option($option_name);
         if (isset($o['ga_oauth']['oauth_token']) && $o['ga_oauth']['oauth_token'] == $_REQUEST['oauth_token']) {
             $gdata = new WP_GData(array('scope' => 'https://www.google.com/analytics/feeds/', 'xoauth_displayname' => 'Google Analytics by Yoast'), $o['ga_oauth']['oauth_token'], $o['ga_oauth']['oauth_token_secret']);
             $o['ga_oauth']['access_token'] = $gdata->get_access_token($_REQUEST['oauth_verifier']);
             unset($o['ga_oauth']['oauth_token']);
             unset($o['ga_oauth']['oauth_token_secret']);
             $o['ga_token'] = $o['ga_oauth']['access_token']['oauth_token'];
         }
         update_option($option_name, $o);
         wp_redirect(menu_page_url('yst_ga_settings', false));
         exit;
     }
     if (!empty($_GET['reauth'])) {
         $gdata = new WP_GData(array('scope' => 'https://www.google.com/analytics/feeds/', 'xoauth_displayname' => 'Google Analytics by Yoast'));
         $oauth_callback = add_query_arg(array('ga_oauth_callback' => 1), menu_page_url('yst_ga_settings', false));
         $request_token = $gdata->get_request_token($oauth_callback);
         $options = get_option($option_name);
         if (is_array($options)) {
             unset($options['ga_token']);
             if (is_array($options['ga_oauth'])) {
                 unset($options['ga_oauth']['access_token']);
             }
         }
         $options['ga_oauth']['oauth_token'] = $request_token['oauth_token'];
         $options['ga_oauth']['oauth_token_secret'] = $request_token['oauth_token_secret'];
         update_option($option_name, $options);
         wp_redirect($gdata->get_authorize_url($request_token));
         exit;
     }
 }