Skip to content

Ballerina project to integrate stackoverflow and google sheets

Notifications You must be signed in to change notification settings

ashera96/ballerina-stackoverflow-gsheet

Repository files navigation

Ballerina-Stackoverflow-Spreadsheet Integration

This is a ballerina project to integrate stackoverflow and google sheets

This guide walks you through the process of running this repo which use Stackoverflow and Google Sheets along with Ballerina language.

The following sections provide you with information on how to get started with Stackoverflow Spreadsheet Integration.

What you’ll build

To understand how you can use Ballerina API connectors, in this sample we use StackExhchange API to get data from a user account and we use the Spreadsheet connector to store the retrieved data to a Google Sheet.

You can retrieve what ever details you like from a stack exchange account (question details are retrieved in this scenario), then use the Ballerina Google Spreadsheet connector and store that data to a spreadsheet.

In order to try something other than questions you can check out the stackexchange docs.

Compatibility

Ballerina Language Version Stack Exchange API Version Google Spreadsheet API Version
1.0.1 V2.2 V4

Prerequisites

$ ballerina pull wso2/gsheets4
  • A Text Editor or an IDE

Tip: For a better development experience, install one of the following Ballerina IDE plugins: VSCode, IntelliJ IDEA

Getting Started

Cloning

Clone this repo to a preferred local directory

$ git clone https://github.com/ashera96/ballerina-stackoverflow-gsheet.git

Configurations

  • Go through the following steps to obtain credentials and tokens for Google Sheets API.

    1. Visit Google API Console, click Create Project, and follow the wizard to create a new project.
    2. Enable the Google Sheets APIs for the project.
    3. Go to Credentials -> OAuth consent screen, enter a product name to be shown to users, and click Save.
    4. On the Credentials tab, click Create credentials and select OAuth client ID.
    5. Select an application type, enter a name for the application, and specify a redirect URI (enter https://developers.google.com/oauthplayground if you want to use OAuth 2.0 playground to receive the authorization code and obtain the access token and refresh token).
    6. Click Create. Your client ID and client secret appear.
    7. In a separate browser window or tab, visit OAuth 2.0 playground, select the required Google Sheets API V4 scopes, and then click Authorize APIs.
    8. When you receive your authorization code, click Exchange authorization code for tokens to obtain the refresh token and access token.
  • Go through the following steps to obtain credentials for Stack Exchange API.

    1. Get your stackoverflow user id
  • Create a Google Sheet as follows from the same Google account you have obtained the client credentials and tokens.

Image of the created spreadsheet

  • Obtain the spreadsheet id by extracting the value between the "/d/" and the "/edit" in the URL of your spreadsheet.

    You must configure the ballerina.conf configuration file with the above obtained tokens, credentials and other important parameters as follows.

    ACCESS_TOKEN="access token"
    CLIENT_ID="client id"
    CLIENT_SECRET="client secret"
    REFRESH_TOKEN="refresh token"
    SPREADSHEET_ID="spreadsheet id you have extracted from the sheet url"
    SHEET_NAME="sheet name of your Goolgle Sheet. For example in above example, SHEET_NAME="StackoverflowQuestions"
    STACKOVERFLOW_ID="stackoverflow id"
    

    At the end of this step you should have a ballerina.conf configuration file at the same level of Ballerina.toml with filled parameters.

Building

$ ballerina build -a

After the build is successful, there will be a .jar file inside the target directory. That executable can be executed as follows.

Running

$ ballerina run target/bin/stackoverflow_gsheet.jar

If the above mentioned instructions were properly followed the retrieved details should be added to the spreadsheet as shown below.

Image of the spreadsheet with the retrieved data

About

Ballerina project to integrate stackoverflow and google sheets

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published