Zamalekk
Zamalekk

Reputation: 1

Google Analytics PHP API Redirect URI

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.

Upvotes: 0

Views: 1928

Answers (1)

Jan Gerlinger
Jan Gerlinger

Reputation: 7415

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.
$client->setClientId('insert_your_oauth2_client_id');
$client->setClientSecret('insert_your_oauth2_client_secret');
$client->setRedirectUri('insert_your_oauth2_redirect_uri');
$client->setDeveloperKey('insert_your_developer_key');
$client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly'));

Upvotes: 1

Related Questions