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.
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.
Ballerina Language Version | Stack Exchange API Version | Google Spreadsheet API Version |
---|---|---|
1.0.1 | V2.2 | V4 |
- Ballerina Distribution
- You can pull the Spreadsheet client from Ballerina Central:
$ 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
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.
- Visit Google API Console, click Create Project, and follow the wizard to create a new project.
- Enable the Google Sheets APIs for the project.
- Go to Credentials -> OAuth consent screen, enter a product name to be shown to users, and click Save.
- On the Credentials tab, click Create credentials and select OAuth client ID.
- 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).
- Click Create. Your client ID and client secret appear.
- 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.
- 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.
- Get your stackoverflow user id
-
Create a Google Sheet as follows from the same Google account you have obtained the client credentials and tokens.
-
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 ofBallerina.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.