Take the 2-minute tour ×

I'm testing the Google Analytics API (with oauth 2.0) on my local machine and I want to know if it's possible to get it to work this way as they request me to insert a Redirect URI in the Google APIs Console and then enter it in my code but I do not know what this Redirect URI should be?

My current Redirect URI is https://localhost/oauth2callback and I tried https://gapi.local/oauth2callback but neither works for me.

I get this error message:
Fatal error: Call to undefined method apiClient::setClientRedirectUri() in C:\xampp\htdocs\webs\gapi\HelloAnalyticsApi.php on line 15

Any help would be appreciated.

share|improve this question
When does that error happen? Before redirecting? After you were redirected back? If the browser was redirected back, does it actually run any line of your code? –  Jan Gerlinger Aug 20 '12 at 10:19
The problem is that no redirection occurs. When I run the file, it's supposed to display the amount of visitors to the site of my GA account but it just displays the error message above. I used the exact same code as in this tutorial: developers.google.com/analytics/resources/tutorials/… –  Zamalekk Aug 20 '12 at 11:08
add comment

1 Answer

up vote 1 down vote accepted

The google-api-php-client library has no method setClientRedirectUri() in apiClient. The correct method is called setRedirectUri():

$client = new apiClient();
$client->setApplicationName('Hello Analytics API Sample');

// Visit //code.google.com/apis/console?api=analytics to generate your
// client id, client secret, and to register your redirect uri.
share|improve this answer
Thanks Jan. Embarrassing beginner mistake on my side. –  Zamalekk Aug 21 '12 at 8:01
@VuvuuAdi Could you mark my answer as accepted then? Thanks :) –  Jan Gerlinger Aug 22 '12 at 6:52
add comment

Your Answer


