<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[frustrated_dev]]></title><description><![CDATA[Sharing my web engineering knowledge with the awesome tech community here.]]></description><link>https://raselhasan.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 08 Sep 2026 06:36:31 GMT</lastBuildDate><atom:link href="https://raselhasan.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[I built my own Google Calendar Event Scheduler with FastAPI]]></title><description><![CDATA[Hey Codemonkey!
I'm introducing a simple FastAPI-based application that allows users to schedule and manage events using the Google Calendar API. This app integrates Google OAuth for authentication, enabling event creation and retrieval from a user's...]]></description><link>https://raselhasan.hashnode.dev/i-built-my-own-google-calendar-event-scheduler-with-fastapi</link><guid isPermaLink="true">https://raselhasan.hashnode.dev/i-built-my-own-google-calendar-event-scheduler-with-fastapi</guid><category><![CDATA[FastAPI]]></category><category><![CDATA[Google Calendar integration]]></category><category><![CDATA[google Oauth]]></category><category><![CDATA[Python 3]]></category><dc:creator><![CDATA[Rasel Hasan]]></dc:creator><pubDate>Wed, 18 Sep 2024 19:03:11 GMT</pubDate><content:encoded><![CDATA[<h1 id="heading-hey-codemonkey">Hey Codemonkey!</h1>
<p>I'm introducing a simple FastAPI-based application that allows users to schedule and manage events using the Google Calendar API. This app integrates Google OAuth for authentication, enabling event creation and retrieval from a user's Google Calendar.</p>
<h2 id="heading-features">Features</h2>
<ul>
<li>Google OAuth2 for user authentication.</li>
<li>Fetch upcoming events from the user's primary Google Calendar.</li>
<li>Create new events on the user's Google Calendar.</li>
<li>In-memory token storage for authenticated users (single-user session) to keep the project simple.</li>
</ul>
<h2 id="heading-project-structure">Project Structure</h2>
<pre><code class="lang-plaintext">google-calendar-event-scheduler/
│
├── app/
│   ├── api/
│   │   ├── auth.py            # Handles authentication routes
│   │   ├── events.py          # Handles event-related routes
│   │   └── __init__.py        # Imports FastAPI routes from different modules
│   ├── core/
│   │   ├── config.py          # Configuration for environment variables and settings
│   │   └── auth_flow.py       # Google OAuth flow setup and helper functions
│   ├── models/
│   │   ├── event.py           # Pydantic models for request/response schemas
│   │   └── __init__.py        # Imports all models
│   ├── services/
│   │   ├── calendar.py        # Calendar service interactions
│   │   └── __init__.py
│   ├── __init__.py            # Initialize FastAPI app
│   └── main.py                # Entry point for the application
├── .env                       # Environment variables, ignored from git tracking
├── .env.example               # Environment variables example
└── requirements.txt           # Dependencies
</code></pre>
<h2 id="heading-pre-requisites">Pre-requisites</h2>
<ul>
<li><p>Python 3.12</p>
</li>
<li><p>A Google Cloud project with Google Calendar API and OAuth credentials.</p>
</li>
<li><p>Virtual environment (venv)</p>
</li>
</ul>
<h2 id="heading-setting-up-google-oauth">Setting up Google OAuth</h2>
<ol>
<li><p>Go to the Google Cloud Console.</p>
</li>
<li><p>Create a project and enable the Google Calendar API.</p>
</li>
<li><p><strong>Set-up OAuth 2.0 credentials:</strong> Authorized redirect URIs should match the one used in the .env file.</p>
</li>
<li><p>Download the OAuth client credentials and place them in your .env file.</p>
</li>
</ol>
<h2 id="heading-environment-variables">Environment Variables</h2>
<ul>
<li>Create a <em>.env</em> file in the root directory with the following contents same as <em>.env.example</em> file:</li>
</ul>
<pre><code class="lang-plaintext">GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret
GOOGLE_REDIRECT_URI=http://localhost:8000/auth/redirect
GOOGLE_SCOPES=https://www.googleapis.com/auth/calendar
</code></pre>
<h2 id="heading-installation">Installation</h2>
<h3 id="heading-clone-the-repository"><strong>Clone the repository:</strong></h3>
<pre><code class="lang-plaintext">git clone https://github.com/raselhasan111/google-calendar-event-scheduler.git
cd google-calendar-event-scheduler
</code></pre>
<h3 id="heading-create-and-activate-a-virtual-environment"><strong>Create and activate a virtual environment:</strong></h3>
<pre><code class="lang-plaintext">python3 -m venv venv
source venv/bin/activate  # On Windows use `venv\Scripts\activate`
</code></pre>
<h3 id="heading-install-dependencies"><strong>Install dependencies:</strong></h3>
<pre><code class="lang-plaintext">pip install -r requirements.txt
</code></pre>
<p><strong>And set up your environment variables in .env (as shown above).</strong></p>
<h2 id="heading-running-the-application">Running the Application</h2>
<h3 id="heading-start-the-fastapi-app-using-uvicorn">Start the FastAPI app using Uvicorn:</h3>
<pre><code class="lang-plaintext">uvicorn app.main:app --reload
</code></pre>
<p><strong>The app will be running at <em>http://127.0.0.1:8000.</em></strong></p>
<h3 id="heading-endpoints">Endpoints</h3>
<ul>
<li>Login with Google OAuth</li>
</ul>
<pre><code class="lang-plaintext">Endpoint: /auth/login
Method: GET
Description: Redirects the user to Google's OAuth2 login page.
</code></pre>
<ul>
<li>Handle OAuth Redirect</li>
</ul>
<pre><code class="lang-plaintext">Endpoint: /auth/redirect
Method: GET
Description: Handles the OAuth2 callback and saves the access token.
</code></pre>
<ul>
<li>Get Events</li>
</ul>
<pre><code class="lang-plaintext">Endpoint: /events
Method: GET
Description: Fetches up to 10 upcoming events from the user's Google Calendar.
</code></pre>
<ul>
<li>Create Event</li>
</ul>
<pre><code class="lang-plaintext">Endpoint: /events
Method: POST
Description: Creates a new event in the user's Google Calendar.
</code></pre>
<p><strong>Sample Request:</strong></p>
<pre><code class="lang-json">{
    <span class="hljs-attr">"summary"</span>: <span class="hljs-string">"Project Kickoff Meeting"</span>,
    <span class="hljs-attr">"description"</span>: <span class="hljs-string">"Discussing the new project with the team."</span>,
    <span class="hljs-attr">"start"</span>: {
        <span class="hljs-attr">"dateTime"</span>: <span class="hljs-string">"2024-10-15T09:00:00-07:00"</span>,
        <span class="hljs-attr">"timeZone"</span>: <span class="hljs-string">"America/Los_Angeles"</span>
    },
    <span class="hljs-attr">"end"</span>: {
        <span class="hljs-attr">"dateTime"</span>: <span class="hljs-string">"2024-10-15T10:00:00-07:00"</span>,
        <span class="hljs-attr">"timeZone"</span>: <span class="hljs-string">"America/Los_Angeles"</span>
    },
    <span class="hljs-attr">"location"</span>: <span class="hljs-string">"Google Meet"</span>,
    <span class="hljs-attr">"attendees"</span>: [<span class="hljs-string">"email@example.com"</span>]
}
</code></pre>
<p><strong>Open <em>http://127.0.0.1:8000/docs</em> to test endpoints with swagger.</strong></p>
<h4 id="heading-now-its-your-time-to-plug-and-play-happy-coding">Now it's your time to plug and play, happy coding!</h4>
<h4 id="heading-source-code-github-repositoryhttpsgithubcomraselhasan111google-calendar-event-scheduler"><a target="_blank" href="https://github.com/raselhasan111/google-calendar-event-scheduler">Source Code: Github Repository</a></h4>
]]></content:encoded></item></channel></rss>