This video shows the steps to setup OAuth 2.0 authentication for Google(GCP) account to work with Gemini APIs on Desktop applications.
It uses reference from the below page:
https://ai.google.dev/gemini-api/docs/oauth?authuser=2
I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: programmerworld1990@gmail.com
Test API:
access_token=$(gcloud auth application-default print-access-token)
project_id=<MY PROJECT ID>
curl -X GET https://generativelanguage.googleapis.com/v1/models \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${access_token}" \
-H "x-goog-user-project: ${project_id}" | grep '"name"'
Sample:
curl -X GET https://generativelanguage.googleapis.com/v1/models \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ya29.a0AXooCgtiU4KYu7aEX0dBKywZX0t5XGjWbwEoPjI22zoq9id9Y2V_vfXgtiGOlsRtulJCzsyWlhGUdZR2tcoGU-VCnKx8I9giUCC3RhUk1_-2wgutYs7AazercDU345YG7MdKKg0AOZBB7NinD8ivxUGNnisYBFD20ZfBgaCgYKAV8SARESFQHGX2Mi0xuHC9KcOkm4bUyJlyOjWAO173" \
-H "x-goog-user-project: apt-mark-400702" | grep '"name"'
Successfully running the test API:
Error in Test API if given wrong token:
Other Screenshots:
Make sure to use Windows PowerShell to run the gcloud command (and don’t use simple windows command prompt):
PS C:\Work\GeminiAPI> gcloud auth application-default login --client-id-file=client_secret.json --scopes='https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/generative-language.retriever'
Your browser has been opened to visit:
https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=808443943433-uh9sqecg75ai5r97krd51sqhslo228aq.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8085%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgenerative-language.retriever&state=4lax4dDoAC2vhPKhtRYzd7R9QPNPH6&access_type=offline&code_challenge=QlZw228wAi5bhHvY6Pma1-QiaRoDWNbWrXqF8FgxGrI&code_challenge_method=S256
Credentials saved to file: [C:\Users\abhis\AppData\Roaming\gcloud\application_default_credentials.json]
These credentials will be used by any library that requests Application Default Credentials (ADC).
PS C:\Work\GeminiAPI> gcloud auth application-default print-access-token
ya29.a0AXooCgsUmGv6y7_ePG1BfZDezsq5O0jzxhXNeTGIFmXI5bc506qgg8MNceg_jbSBHs2mzkJAcv4Lxop15EaKqbmkfBcn5oQpbQ-VyCNuUK3lfnrilspbZ7snHOzlGgE50Vu2n0Js0o13jvtN23sUOXD-I4hMpz5CJaCgYKAZUSARMSFQHGX2MihJj9iQ2wMBzlgy1MWDVrBw0171
PS C:\Work\GeminiAPI>