How to authorize in google api with my credentials or special generated identifiers and passwords?

I want to get all my events from my personal calendar. I tried for several hours all kinds of auth types: I successfully performed a callback authorization, where I need to log in to my google account and then redirect Google to my site. β€œBut that's not what I need.” Also, I tried with the default credentials, and, to my surprise, I don't have access to my calendar, what kind of logic is it.

Basically, how it works for me in Spotify: in Spotify, you can generate a client ID and password in my account. After that, I send HTTP with base64 (client: password) in my header from my code and the receiving token, which I use to request some objects.

But in google API I did not find such a solution. Maybe someone can advise how to authenticate?

+5
source share
1 answer

You can use the Google client library for PHP . He noted beta , but I found it easy to use, and it works great for simple uses of the Calendar.

I put a working example on GitHub.

If you prefer to use the code directly against the OAuth 2.0 API, I would recommend checking out Google Developers OAuth 2.0 Playgrounds .

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

This allows you to observe the authentication flow, starting with redirecting back to your application after the user authenticates and grants permissions using 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/ user@gmail.com /events HTTP/1.1 Host: www.googleapis.com Content-length: 0 Authorization: Bearer ya29.GlsBBUxxxxxxxxxxXo-dF-Kexxxxxxxxxxxx0j_owVSaxxxxxxxxxWG-Xxxxxxxxxl 
+3
source

Source: https://habr.com/ru/post/1273186/


All Articles