Search code examples
phpcomposer-phpgoogle-oauthcodeigniter-3google-api-php-client

Google service "Oauth2" does not exist or was removed previously - Composer


I am using google oAuth for the Codeigniter application with this composer library "google/apiclient": "^2.10", for the login, and works fine on local environment. But it downloaded all the google services and I don't want to upload all unnecessary libraries to the server. So I removed all by using the following configuration file.

composer.json file

{
"require": {
    "google/apiclient": "^2.10",
    "google/auth": "^1.16"
},
"scripts": {
    "pre-autoload-dump": "Google\\Task\\Composer::cleanup"
},
"extra": {
    "google/apiclient-services": [
        "Drive",
        "YouTube"
    ]
}

}

But then I received an error page on the application while authentication

An uncaught Exception was encountered Type: Error Message: Class "Google_Service_Oauth2" not found

So I added appropriate library "Oauth2" and run the `composer update' command.

{
"require": {
    "google/apiclient": "^2.10",
    "google/auth": "^1.16"
},
"scripts": {
    "pre-autoload-dump": "Google\\Task\\Composer::cleanup"
},
"extra": {
    "google/apiclient-services": [
        "Drive",
        "YouTube",
        "Oauth2"
    ]
}

}

The problem is "Oauth2" library is not adding to the existing project using composer.

Note: I have tried to update without "pre-autoload-dump": "Google\\Task\\Composer::cleanup" line and still it doesn't work.

Is there any way to fix this using a composer file or command. Thank you for the help.

enter image description here


Solution

  • Thank you community and I just found the answer.

    I have to delete the apiclient-services folder completed and then need to run the composer update command.

    Source: IMPORTANT: If you add any services back in composer.json, you will need to remove the vendor/google/apiclient-services directory explicitly for the change you made to have effect:

    google-api-php-client