Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I auth in google api with my credentials or special generated id and password?

I want to get all my events from my personal calendar. I have tried for hours all kind of auth types: I did successfully auth with callback, where I should login to my google account and then google redirects back to my website. - but this is not what I need. Also I have tried with default credentials, and on my surprise, I don't have access to my calendar, what kind of logic is this.

Basically, how its working for me in Spotify: in Spotify it is possible to generate client id and password in my account. After that I send HTTP with base64(client:password) in my header from my code and receiving token, which I use to query some entities.

But in google API I didn't find such solution. Maybe someone could advice how to authenticate?

like image 537
Aleksandrs Avatar asked Oct 18 '22 03:10

Aleksandrs


1 Answers

You could use the Google client library for PHP. It's marked beta, but I found it easy to use and it works just fine for simple Calendar use cases.

I put a working example out on GitHub.

If you would rather code directly against the OAuth 2.0 APIs, I'd recommend checking out the Google Developers OAuth 2.0 Playground.

  • Select the Calendar API v3 at step 1.
  • At step 3, click List possible operations and select List Events. Replace {calendarId} with your gmail.com email address.

This allows you to observe the auth flow, starting with the redirect back to your application after the user authenticates and grants permissions with Google:

GET /oauthplayground/?code=4/xxxxxxxxxxxZL-nxhM_kxxxxxxxxxQ HTTP/1.1

POST /oauth2/v4/token HTTP/1.1
Host: www.googleapis.com
Content-length: 233
content-type: application/x-www-form-urlencoded
user-agent: google-oauth-playground
code=4%2FxxxxxxxxxxxxxxZL-xxxx_kxxxxxxxxxxQ&redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&client_id=4xxxxxxxxxx.apps.googleusercontent.com&client_secret=************&scope=&grant_type=authorization_code

GET /calendar/v3/calendars/[email protected]/events HTTP/1.1
Host: www.googleapis.com
Content-length: 0
Authorization: Bearer ya29.GlsBBUxxxxxxxxxxXo-dF-Kexxxxxxxxxxxx0j_owVSaxxxxxxxxxWG-Xxxxxxxxxl
like image 161
Mike Patrick Avatar answered Oct 21 '22 08:10

Mike Patrick