Ich habe versucht, das offizielle HelloAnalytics Tutorial, aber es funktioniert nicht.Auth Google Analytics PHP API
Ich recieveing diesen Fehler:
"PHP Fatal error: Class 'Google_Auth_AssertionCredentials' not found"
Mein Code:
// Creates and returns the Analytics service object.
// Load the Google API PHP Client Library.
require_once 'vendor/autoload.php';
// Use the developers console and replace the values with your
// service account email, and relative location of your key file.
$service_account_email = '[email protected]';
$key_file_location = 'key_anyl.p12';
// Create and configure a new client object.
$client = new Google_Client();
$client->setApplicationName("HelloAnalytics");
$analytics = new Google_Service_Analytics($client);
// Read the generated client_secrets.p12 key.
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_email,
array(Google_Service_Analytics::ANALYTICS_READONLY),
$key
);
$client->setAssertionCredentials($cred);
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
Update:
nach den vorgeschlagenen V1-Master-Zweig hinzugefügt ich jetzt immer die Folgefehler
Uncaught exception 'Google_Service_Exception' with message 'Error calling GET googleapis.com/analytics/v3/management/accounts: (403) User does not have any Google Analytics account.'
Wenn Sie keinen Composer verwenden, stellen Sie sicher, dass Sie den v1-master-Zweig heruntergeladen haben https://github.com/google/google-api-php-client/tree/v1-master – DaImTo
thx Ich habe diese Version ausprobiert, aber jetzt i Erhalte diesen Fehler Uncaught-Ausnahme 'Google_Service_Exception' mit Nachricht 'Fehler beim Aufruf von GET https://www.googleapis.com/analytics/v3/management/accounts: (403) Der Nutzer hat kein Google Analytics-Konto.' – glanaj
Überprüfen Sie die Antwort, die ich gerade hinzugefügt habe. Das wird zu lang für Kommentare. – DaImTo