Can’t configure Google Analytics Reports – “Invalid Token” message

When behind a proxy, Google Analytics Reports module in apache throws a “invalid token” message.

Solution:

The drupal_http_request does not handle corporate proxies well. Here is the custom function that I wrote to fix this exact issue:

 

function curl_http_request($url, $headers, $method, $data)
{
$result = new stdClass();
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,$url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $gacookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $gacookie);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt ($ch, CURLOPT_PROXY, "myproxyserver.mydomain.com");
curl_setopt ($ch, CURLOPT_PROXYPORT, 80);
curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, $method);
$fetched = curl_exec ($ch);
$result->code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$result->data = $fetched;
$result->error = curl_errno($ch);
curl_close($ch);
return($result);
}

Replace drupal_http_request in GA.lib.inc, with this function curl_http_request. It works for me. YMMV

Note: This can be used in place of drupal_http_request