๐๐ผ๐ผ๐ด๐น๐ฒ ๐๐๐๐ต ๐๐ป ๐ก๐ผ๐ฑ๐ฒ ๐๐ฆ ๐ช๐ถ๐๐ต๐ผ๐๐ ๐ฃ๐ฎ๐ฐ๐ธ๐ฎ๐ด๐ฒ๐
The googleapis package is common for Node.js. It is heavy. It adds 450 dependencies to your project. You do not need this for a simple CI script.
I wrote a script for the Search Console API. It is 60 lines long. It uses built-in Node.js tools. It adds zero packages to the repo.
The process is simple:
- Create a JWT with your service account email and private key.
- POST the JWT to the Google token endpoint.
- Get an access token.
- Use the token as a Bearer header in your API requests.
Keep these tips in mind:
- Use the webmasters scope.
- Use webmasters.readonly for URL Inspection.
- Use base64url encoding.
- Remove padding.
- Replace plus signs with minus signs.
- Replace slashes with underscores.
This method is best for simple scripts. It keeps your code clean.
Use a library if:
- You call many Google APIs.
- You need automatic token refreshes.
- You need retry logic.
- You build production server code.
Knowing the raw flow helps you debug. You see how the JWT becomes a token. This makes you faster.