erebusnz / gapi-google-analytics-php-interface

GA:PI() - Google Analytics PHP Interface
167 stars 86 forks source link

invalid_grant error #121

Closed maxencecalvez closed 9 years ago

maxencecalvez commented 9 years ago

I use gapi to display analytics reports on websites. I have your solution working well on one server but on an other one, it returns this error : " 500 | Internal Server Error | Exception GAPI: Failed to authenticate user. Error: "{ "error": "invalid_grant", "error_description": "Bad Request" } gapi.class.php line 541 gapiOAuth2->fetchToken() line 50 " It's integrated in symfony 1.4 on a 5.2.9 PHP version The server is time synchronised (Windows 2008 R2 => w32tm resync) And since it's working on the other server, I guessed it wasn't a matter of token. Do you have any clue what I'm doing wrong ? Could it be the PHP version is incompatible ? Thanks

maxencecalvez commented 9 years ago

I had to edit the gapi.class.php line 241 from " /**

to " protected function isArray($var) { return !is_array($var); } /**

mujji89 commented 9 years ago

I am getting same error and unfortunately this didn't solved it for me. What was the issue you think it had. I am using xampp with php 5.6 on windows 8.1

maxencecalvez commented 9 years ago

Well, I should had been more specific. I did this correction because the declaration of a function wasn't accepted by my 5.2.9 version of PHP. I still have the invalid_grant error.

mujji89 commented 9 years ago

that error is gone when I enter the email provided in google developer console in service account. Can you try with that and respond.

But now I am getting permission error though i have added it in google analytics user as well

mujji89 commented 9 years ago

Actually it worked now. Use the service email address for authentication and add same email in google analytics user management with permissions. It worked for me after 10-15 mins of adding email in google analytics

erebusnz commented 9 years ago

Invalid_grant error is usually caused by using an invalid service account, for example one that doesn't end in '@developer.gserviceaccount.com' (for example if you used an @gmail.com account). Please confirm that your account is set up OK and has Analytics API access enabled.

maxencecalvez commented 9 years ago

In my case, the mail is correct as it works on an other server. Its format is "*****developer.gserviceaccount.com and the account has the credentials on Google Analytics.

Warface commented 9 years ago

I've created the services account and .p12 key. Analytics API is enabled in the console. Added the services account email with permission "Read & Analyze" in Google Analytics. Waited an hour and still having the 'GAPI: Failed to authenticate user'

Trust me I've followed this thread carefully... I don't know what to do now...