googleworkspace / php-samples

PHP samples for Google Workspace APIs
Apache License 2.0
288 stars 348 forks source link

Fatal error: Uncaught InvalidArgumentException #20

Closed SamMalcolm closed 6 years ago

SamMalcolm commented 6 years ago

(Please search existing issues before creating a new one.)

Sample:

Expected Behavior

Actual Behavior

Terminal throws an error: Fatal error: Uncaught InvalidArgumentException: missing the required redirect URI in /Users/e32398/Sites/composer_test/vendor/google/auth/src/OAuth2.php:650 Stack trace:

0 /Users/e32398/Sites/composer_test/vendor/google/apiclient/src/Google/Client.php(339): Google\Auth\OAuth2->buildFullAuthorizationUri(Array)

1 /Users/e32398/Sites/composer_test/quickstart.php(26): Google_Client->createAuthUrl()

2 /Users/e32398/Sites/composer_test/quickstart.php(58): getClient()

3 {main}

thrown in /Users/e32398/Sites/composer_test/vendor/google/auth/src/OAuth2.php on line 650

Steps to Reproduce the Problem

  1. Installed composer and composer packages
  2. created credentials in API console selecting server side access. Created user for credentials as project owner
  3. Copy php to quickstart.php and ran php quickstart.php

Specifications

asrivas commented 6 years ago

Which quickstart is this from?

bshaffer commented 6 years ago

Hello! So you will need to set the redirect URI in your Google_Client instance before calling createAuthUrl. For example:

$client = new Google_Client();
$client->setRedirectUri('https://mywebsite.com/auth/callback');
$client->setAuthConfig('/path/to/service_account.json');
$url = $client->createAuthUrl();
SamMalcolm commented 6 years ago

@asrivas PHP Quickstart for the google sheets api v4

SamMalcolm commented 6 years ago

I had download an incorrectly configured crednetials.json file as i must have selected the wront prefrences. As suchh im closing this issue, thanks for your input @asrivas and @bshaffer

asrivas commented 6 years ago

No worries, glad you figured it out!