Open filias opened 4 years ago
-- SOME MORE BACKGROUND -- Pyladies Bratislava is managed via a Facebook Account (https://www.facebook.com/pyladies.bratislava.9) and a Facebook Group (https://www.facebook.com/groups/PyLadiesBratislava).
There are Facebook APIs for Facebook Groups containing info about events of the groups (https://developers.facebook.com/docs/graph-api/reference/v8.0/group), however they can be currently accessed only by authorized apps (https://developers.facebook.com/docs/graph-api/reference/v8.0/group/events).
The solution I suggest is to use Zapier app (https://www.zapier.com) which after added to Facebook Group can send events to Pyladies Bratislava Google Calendar (already set). From Google Calendar, we can access events via API (https://developers.google.com/calendar/overview) and use it in Python (https://developers.google.com/calendar/quickstart/python).
Or if anybody sees the better solution, please let me know.
PS: There are also plugins that could be used on websites (https://support.obior.com/en/articles/1816974-how-to-embed-a-facebook-events-list-in-your-website, https://strategybykatie.com/add-google-calendar-apptab-facebook/), but we wanna do it the hard (and hopefully pretty) way ! :)
To access Google calendar API, I followed steps in this link: https://developers.google.com/identity/protocols/oauth2 (yet just the step 1 :D)
IDK which authentification shall be used (https://developers.google.com/identity/protocols/oauth2/web-server) - now web server application used
UPDATE 30/09/2020:
Redirect to localhost URI was authorised here: https://console.developers.google.com/apis/credentials/oauthclient/906474483409-kgm73vb1burl0oravbqqpn49cbn6r0qj.apps.googleusercontent.com?authuser=1&project=pyladiesba-googl-1600865076622 Now, the quickstart.py sample file successfully reaches Google calendar APIs after logging in with bratislava@pyladies.com credentials
A Pylady from Pyladies Slack asked me to share bratislava@pyladies.com's Google calendar with info@pyladies.com which I did. It is to enable Zapier app to send google calendar events from bratislava@pyladies.com's calendar to our #city-bratislava Slack channel. Test event was successfully sent from Pyladies Bratislava Google Calendar to Slack.
From now, events can be created only in Facebook and they will be automatically posted to Pyladies Bratislava Google Calendar and #city-bratislava Slack channel by Zapier
-- continuing on this comment : https://github.com/pyladies-bratislava/website/issues/3#issuecomment-698500493 --
For gaining access for a website to Google Calendar APIs, new project had to be created: link to the project in console.
In this project, in /APIs & Services/Library tab, Google Calendar API has to be enabled. In /APIs & Services/Credentials tab, new OAuth 2.0 Client (Web Application type) has to be created with Authorized redirect URI (for now: http://localhost/, this may be later changed) In /APIs & Services/OAuth Consent tab, new internal type app has to be created (this will be our Flask/FastAPI based website) - named 'Get Events'
After first attempt to access Google Calendar APIs from our Flask app, authorizing this app (our Flask app/FastAPI ) with client_secret.json credentials is needed. Redirection to login with bratislava@pyladies.com google is done, submitting authorization of 'Get Events' application should be done. After exhausting procedure, credentials containing temporal 'access token' and longer lasting 'refresh_token' should be obtained and saved by events.py as a pickle for further usage. Refresh token is gained only on the first authentication and has to be stored! If not, new project has to be created (That is why the old one from the above https://github.com/pyladies-bratislava/website/issues/3#issuecomment-698500493 could not be used).
Access token is used for an hour to access Google Calendar APIs. After timeout, new access token is obtained by using refresh token.
to keep in mind:
The Google Calendar credentials downloaded as .json file from here were added as configuration variables to the bratislava-flask-backend app in heroku and they can be accessed by the app via .json file created by buildpack.
Link to the HOW-TO page
The above written way of obtaining Google Calendar API (via OAuth 2.0 Client ID) required logging in of every visitor of the site, which was not our aim. To gain Google Calendar APIs by our backend site without visitors logging in, we should have used Service Account OAuth2 authorization.
The changes were made to the backend according to: https://developers.google.com/identity/protocols/oauth2/service-account#creatinganaccount
Now the Google Calendar APIs are gained via OAuth 2.0 for Server to Server Applications using Service Account.
-- ISSUE DESCRIPTION -- Pyladies meetups' events are currently managed via Facebook events. For having another way to see the events calendar (e.g. for non facebook users) the idea is to show the events calendar in a Pyladies website.