BenGoogle Analytics gerçek zamanlı activeUsers php olarak nasıl alınır?
$client->setApplicationName("Analytics");
$client->setDeveloperKey("key");
$service = new Google_Service_Analytics($client);
$optParams = array(
'dimensions' => 'rt:medium');
try {
$results = $service->data_realtime->get(
'ga:profileid',
'rt:activeUsers',
$optParams);
// Success.
} catch (apiServiceException $e) {
// Handle API service exceptions.
$error = $e->getMessage();
}
print_r($results);
Bir hata (401) gösterir ... https://github.com/google/google-api-php-client API dosyalarını indirip kodunun altına denedik Girişi Gerekli' i https://console.developers.google.com/project/apps~rational-photon-578/apiui/api/analytics/method/analytics.data.realtime.get
ben çağrıyı çalıştı
Gerekli gerçek zamanlı kullanıcılar profileid ait var.
Peki bunun için bir giriş işlemini (google sitesine gitmeden) nasıl uygulayabilirim? Ben aşağıdaki kodu çalıştı
...
İşte$client_id = 'xxxxxxxxxxxxxxx';
$service_account_name = '[email protected]';
$key_file_location = 'location of .p12 keyfile';
$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
if (isset($_SESSION['service_token'])) {
$client->setAccessToken($_SESSION['service_token']);
}
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array('https://www.googleapis.com/auth/analytics'),
$key
);
$client->setAssertionCredentials($cred);
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$_SESSION['service_token'] = $client->getAccessToken();
echo $_SESSION['service_token'];
$service = new Google_Service_Analytics($client);
$optParams = array(
'dimensions' => 'rt:medium');
try {
$results = $service->data_realtime->get(
'ga:profileid',
'rt:activeUsers',
$optParams);
// Success.
} catch (apiServiceException $e) {
// Handle API service exceptions.
$error = $e->getMessage();
}
print_r($results);
i access_token ve ayrıntıları alıyorum ... ama analiz verisi getirilirken bir hata nedeniyle "yetersiz sayıda izni" başarısız
aldım google konsolundan söz konusu profil kimliğiyle test yaptığımda sonuçlar.
Hey sayesinde .. gerçekten çok yardımcı oldu :) Şimdi ben bir hata "yetersiz sayıda alıyorum gerçek zamanlı kullanıcılara erişim için "izin". Aşağıdaki kodu denedim 'code' $ optParams = dizi ( 'boyutlar' => 'rt: orta'); try { $ sonuçları = $ hizmette-> data_realtime-> get ( 'ga: 123123123', 'rt: activeusers', $ optParams); // Başarı. } catch (apiServiceException $ e) { // API hizmeti istisnalarını işlemek. $ error = $ e-> getMessage(); } 'code' – jpk
Gerçek zamanlı API hala beta sürümde erişim istemeniz gerekiyor. Google, şu anda bir PC'ye erişimim yok. Normalde erişim için 24 saat sürer. – DaImTo
Analitik kullanıcı hesabına e-posta adresini (servis hesabından aldım) ekledim ve izinleri verdim. Bu yüzden bu e-posta adresine erişmek için 24 saat sürecek mi? – jpk