$url2 ='https://www.googleapis.com/analytics/v3/data/realtime?ids=ga%3A104738580&metrics=rt%3AactiveUsers&access_token=.ya29.-QF7_hN0uNhn9iGl8fXB1wFWE7gl_oujmBACEJA5outSg2H5HP28D4mekq6c8tHP2KYn';
//realtime
function get_report($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
$request = curl_getinfo($ch, CURLINFO_HEADER_OUT);
$error = curl_error($ch);
curl_close($ch);
return ($output);
}
POST /oauth2/v3/token HTTP/1.1
Host: www.googleapis.com
Content-Type: application/x-www-form-urlencoded
client_id=1011760424792-huap7gokulbflbcdefrtgls2rsl19n31.apps.googleusercontent.com&
client_secret={SXhE**************-vcox}&
refresh_token=1/3Ww3MOaMHu5Ynwuz9oz3oM0bbtWaQBk_cL7j70g_SIA&
grant_type=refresh_token
--You received this message because you are subscribed to a topic in the Google Groups "Google Analytics Reporting API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-analytics-data-export-api/xVDLAEXpNsg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-analytics-data-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
--
That's exactly what I 've done.
The p12 file is on the same folder so shall I write the path toward him like:
'client_secrets.p12'; ?
function getResults(&$analytics, $profileId) {
// Calls the Core Reporting API and queries for the number of sessions
// for the last seven days.
return $analytics->data_ga->get(
'ga:' . $profileId,
'7daysAgo',
'today',
'ga:sessions');
}
$optParams = array(
'dimensions' => 'rt:medium');
try {
$results = $analytics->data_realtime->get(
'ga:56789',
'rt:activeUsers',
$optParams);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion();
}
Also http://stackoverflow.com/questions/tagged/google-analytics-api is a great place to get help with specific coding issues.
-Matt
--
$analytics = getService();
$profile = getFirstProfileId($analytics);
$optParams = array(
'dimensions' => 'rt:medium');
try {
$results = $analytics->data_realtime->get(
'ga:' . $profile,
'rt:activeUsers',
$optParams);
// Success.
} catch (apiServiceException $e) {
// Handle API service exceptions.
$error = $e->getMessage();
}
function printRealtimeReport($results) {
printReportInfo($results);
}
function printReportInfo(&$results) {
$html = <<<HTML
<pre>
Kind = {$results->getKind()}
ID = {$results->getId()}
Self Link = {$results->getSelfLink()}
Total Results = {$results->getTotalResults()}
</pre>
HTML;
print $html;
}
Nam's