<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Pedro Hase</title>
    <description>The latest articles on Forem by Pedro Hase (@pedrohase).</description>
    <link>https://forem.com/pedrohase</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F762925%2F3671e8a1-4f5a-494d-bcaa-1d9a46372085.png</url>
      <title>Forem: Pedro Hase</title>
      <link>https://forem.com/pedrohase</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/pedrohase"/>
    <language>en</language>
    <item>
      <title>Create Google Calender Events using the Google API and Service Accounts in Node.JS</title>
      <dc:creator>Pedro Hase</dc:creator>
      <pubDate>Wed, 30 Mar 2022 18:06:40 +0000</pubDate>
      <link>https://forem.com/pedrohase/create-google-calender-events-using-the-google-api-and-service-accounts-in-nodejs-22m8</link>
      <guid>https://forem.com/pedrohase/create-google-calender-events-using-the-google-api-and-service-accounts-in-nodejs-22m8</guid>
      <description>&lt;p&gt;If you ever wanted to create Google Calendar Events in NodeJS without having to use OAuth2 (and thus not having to ask users for their permissions), then this article is just for your.&lt;/p&gt;

&lt;p&gt;To do so we will employee so-called Google Cloud "Service accounts" which allow to interact with the API as an application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Go to the Google Cloud Console and create a new project.&lt;/li&gt;
&lt;li&gt;Enable the &lt;a href="https://console.cloud.google.com/marketplace/product/google/calendar-json.googleapis.com"&gt;Calendar API&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/workspace/guides/create-credentials#create_a_service_account"&gt;Create a service account&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;In your calendar where you want to create events, go to the settings and share the calendar with &lt;a href="https://console.cloud.google.com/iam-admin/serviceaccounts"&gt;the e-mail of your service account&lt;/a&gt; (Make sure to set the permissions to &lt;strong&gt;"Make changes to events"&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developers.google.com/workspace/guides/create-credentials#create_credentials_for_a_service_account"&gt;Create and save the credentials JSON for your created account&lt;/a&gt; into your Node.JS project&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;

&lt;p&gt;First you need to install &lt;code&gt;googleapis&lt;/code&gt; and &lt;code&gt;google-auth-library&lt;/code&gt; in your Node.JS project. Then just plug in the function below to create a new event 🙂&lt;/p&gt;

&lt;p&gt;Make sure that you set the calendar ID of the calendar where you want to create the events and that your downloaded &lt;code&gt;credentials.json&lt;/code&gt; is in the right place.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;P.S.: Using this approach you can also interact with any other Google Services. Just make sure that your service account has the right permissions and or that the APIs are enabled and the correct scopes are set 😉.&lt;/p&gt;

</description>
      <category>node</category>
      <category>gcalendar</category>
      <category>google</category>
      <category>api</category>
    </item>
  </channel>
</rss>
