Learn with a PHP OAuth2 Example Google API Access From the Console
01-11-2023 | 17:37 | Manuel Lemos
Read this article to learn how to develop PHP scripts that can get OAuth2-based tokens to access a Google API from the console or as a task executed by corn.
OAuth is a protocol often used to access API on behalf of a user that grants permissions to access the services of an API on behalf of that user.
This allows applications to call APIs even when the user is not present accessing a Web page.
This is possible because the OAuth protocol can be used by Web services to provide token string values that applications can use to access the APIs whenever they want, using a token string as evidence that the user granted permission to access the APIs anytime the application runs.
So, what applications need to do to access an API from a console or a task started with the cron tool is to obtain that token string.
That needs to happen with the presence of the user. The user needs to go to a page of the application. There, the user browser is redirected to a page of the API service provided. The user is requested to permit the application to perform specific actions by calling the API.
[OAuth permission request page image]
After the user provides the requested permissions, the user's browser is redirected back to the application page. Then, the application calls the API following the OAuth protocol to retrieve the access token.
[OAuth application page showing the access token image]
From now on, the application can use the access token to perform API calls to which the user gave permission.

































