Build a Twitter logger
This Twitter logger guide will walk you through both read and write integrations with a Portway project. While funneling the raw madness of Twitter into a Portway document may be a questionable endeavor, it does demonstrate how to use Portway as a two-way street, with data in and out.
This integration will allow you to add a tweet url in a Portway document and see replies to the tweet automatically written to the document.
This guide will walk you through the following setup:
- You will need to sign up for a Twitter Developer Account. For this tutorial the Standard APIs will do everything required.
- You will need to clone and run the Portway Tweet Logger.
Setting up the Tweet Logger
Create a Twitter app
- Sign up and apply for a Twitter Developer Account. Access to the Standard APIs should be approved quickly. You will need a Twitter account.
- Once you have an approved Twitter Developer Account, create a new Twitter app. Many of the fields are not required.
- Save the Twitter app's API key and API secret key. You will need these to use the Twitter API.
Setup the Portway Tweet Logger app
- Clone the Portway Tweet Logger
This assumes you have nvm installed and running locally.
Run the following commands in your terminal:
$ git clone email@example.com:BonkeyBong/portway-tweet-logger.git $ cd portway-tweet-logger $ nvm use $ npm install $ cp example.env .env
- Open the
.envfile in an editor to add the Twitter API keys
TWITTER_API_KEY=[Value from step 3] TWITTER_API_SECRET=[Value from step 3]
Setup a Portway project
- Create a Portway project for Tweet logging
- Navigate to the Project Settings page and choose the "API Keys" from the menu
- Select "Add Project Key" and give your key a name, such as "Portway Twitter Key." Make sure your key has the "Contributor" role so it can read and write data to your project.
- Copy the key and in your
.envfile you edited in Step 5, add the value to
- Now add the
.envfile as well. You can find the project id by looking at the url in Portway when you're viewing the project. You will see a url like
https://portway.app/d/project/44, the number after
project/is the project ID.
Run the Portway Tweet Logger app
- You should now be able to run the Portway Tweet Logger script, which will periodically check for new documents in your project. From the directory where you cloned the app in Step 4, run
Let's log some Tweets!
Ok, you should now have the Portway Tweet Logger running in your terminal. You should see output logging each attempt to find tweet documents.
Logging a Tweet
- In your Portway project, add a new document.
- Create a new "String" data field by clicking the "+" icon in the bottom toolbar
- Rename the field
tweetand set the value to the url of any* Tweet
- Open the document outline mode by clicking the gear icon in the upper right. Delete all other fields in the document besides your "tweet" string. By default, new documents will have a text area that needs to be deleted.
- Publish your document!
- Now watch the Portway Tweet Logger in your terminal, you should see it find the new document. As soon as it does, refresh the document in the Portway app. It will now have additional fields added and replies, if found.
You can keep the Tweet logger script running as long as you want and continue to publish new documents with new Tweets.
The joy of logging Tweets
Now you've gotten a glimpse of the ability to both read and write data from a Portway document. While we don't recommend attempting to log every Tweet published on Twitter (Twitter's API rate limits and Portway's API rate limits won't let you anyway, sorry), the ability to interact with Portway projects through both human and machine interactions can be very powerful.
- Note that due to Twitter API limitations, to get Tweet replies the Tweet should be from the last 7 days. Replies are most likely to be found on an account that doesn't get too many @mentions, otherwise replies may not be findable through the limited Twitter search API.