Juicy
Juicy

Reputation: 12510

Google API PHP: Uncaught Exception on createAuthURL()?

I've just downloaded the latest Google API PHP and I'm trying it out with a "log in with Google" script. The API is throwing this exception that is apparently uncaught:

Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'No scopes specified' in /home/rlcoachi/public_html/hidden/googlelogin/src/Google/Client.php:178 Stack trace: #0 /home/rlcoachi/public_html/hidden/googlelogin/src/Google/Client.php(237): Google_Client->prepareScopes() #1 /home/rlcoachi/public_html/hidden/googlelogin/api.php(76): Google_Client->createAuthUrl() #2 {main} thrown in /home/rlcoachi/public_html/hidden/googlelogin/src/Google/Client.php on line 178

Line 74-77 of my api.php script is:

else 
{
    //For Guest user, get google login url
    $authUrl = $gClient->createAuthUrl();
}

gClient being a Google_Client object that's been setup with id, secret, url, key

Full script is available here

Upvotes: 2

Views: 3147

Answers (2)

itzmukeshy7
itzmukeshy7

Reputation: 2677

Go to file named googlelogin/src/Google/Client.php

search

protected $scopes = array();

then fill the array with scopes like

protected $scopes = array("userinfo.email", "userinfo.profile");

if you want to get user emailId as well as profile details...

Upvotes: 1

Pham
Pham

Reputation: 441

try:

$client->setScopes(array(
     'https://www.googleapis.com/auth/plus.login',
     'profile',
     'email',
     'openid',
));

Upvotes: 1

Related Questions