HTTP Request and Google API

Post Reply
cedric.sintes
Newbie
Posts: 2
Joined: Fri Feb 15, 2013 4:38 pm

HTTP Request and Google API

Post by cedric.sintes »

Hello Switch Users,

I need to send some metadata to a google sheet (and also create events in calendar). The goal is to monitor the progress of jobs and scheduling jobs into printer's calendar.
I think use HTTP request to connect to Google API, create and update Google Sheet with JobId, Customer Name, Delivery Date, ... and create an event in the printer's calendar with metadata (theorical time of event is a calculation of printing surface).

Did someone already connect Switch with Google API ? I have some problems with authentification...

https://developers.google.com/sheets/api/
https://developers.google.com/google-apps/calendar/

Thanks for help.
Padawan
Newbie
Posts: 12
Joined: Mon Jun 12, 2017 8:48 pm

Re: HTTP Request and Google API

Post by Padawan »

I've experimented with 3 legged OAuth before, but I'm far from an expert in it.

Technically, the App had to open a webpage for the user where he could allow the App to access the information of his account, then the API redirected to an URL of the app creator choice with parameters which had to be used as token by the app to be able to consume the API.

To my knowledge, that's all stuff which is not possible in Switch at the moment. Therefore I experimented with this tool:
https://code.google.com/archive/p/oacurl/

It's basically a minimal version of curl written in Java, but which handles the OAuth stuff for you. It was originally written to work with Google API's (although it is not limited to that), so it might be the tool you need.

I didn't create a Switch script with this tool yet, so you might run into issues I'm not aware of.

Edit: Also, I'm just assuming the API's you mention use 3 legged OAuth since the oacurl page mentions google uses this method in the past for authentication.
ChrisBradley
Newbie
Posts: 1
Joined: Mon Jan 01, 2024 6:45 am

Re: HTTP Request and Google API

Post by ChrisBradley »

Certainly! Integrating Switch with Google APIs for data transfer and calendar events requires authentication via OAuth 2.0 for secure access. To troubleshoot authentication issues:
  • Verify OAuth Credentials: Ensure your OAuth credentials (client ID, client secret) are correctly set up in the Google Cloud Console. Properly configured credentials are crucial for authentication.

    Authorization Flow: Double-check the authorization flow in your code. Ensure that Switch is correctly obtaining and sending the OAuth tokens in the HTTP requests to Google APIs for accessing Google Sheets and Calendar.

    Scope Permissions: Confirm that your OAuth tokens have the necessary scopes ('https://www.googleapis.com/auth/spreadsheets' for Sheets and 'https://www.googleapis.com/auth/calendar' for Calendar) to perform the intended actions.

    Handle Token Expiry: OAuth tokens have expiration times. Ensure your integration is set up to handle token refreshes when they expire to maintain continuous access.

    Error Handling: Implement robust error handling to capture and handle specific authentication-related errors. This might provide more detailed insights into what's causing the authentication problems.

    Documentation and Community Support: Refer to Google API documentation and community forums. Often, similar authentication issues and their solutions are discussed and resolved within these resources.
Regarding Switch specifically integrating with Google APIs, review Switch's documentation or community forums for any specific guidelines or known issues related to Google API authentication.

By troubleshooting OAuth authentication meticulously, ensuring proper scopes, handling token refreshes, and consulting relevant resources, you can resolve authentication issues and proceed to create and update Google Sheets while also scheduling events in the printer's calendar seamlessly within Switch.
Post Reply