Abstract
Added a feature to post a tweet with a generated image using Twitter Web Intent.
Motivation
It is mainly assumed that generated images will be posted to Twitter, but currently it is necessary to go to the Twitter application and post the images by oneself. Therefore, the following four steps must be taken before an image is attached to a tweet.
- Copy the image
- Go to the Twitter application.
- Display the pop-up to create a tweet
- Attach the image
It is very time-consuming to do this for every tweet.
Approach
Use Twitter Web Intent. This approach requires only one step before an image can be tweeted.
- Click "Tweet" button.
Problem and Solution
Since Twitter Web Intent does not allow direct pasting of images, it is necessary to use some method to represent images as text. The following two methods can be used to represent images as text, but in consideration of edge cases, I chose the first method.
- Represent an image as the URL of the Twitter image server
- In Twitter, at least images associated with tweets is represented as this URL.
- Pros: Wide range of sizes to view entire images
- Cons: Low scalability (to support other applications such as Slack or Discord, a separate button must be added)
- Set OGP for each image URL
- Pros: High scalability
- Cons: Difficult to implement, large image size can be seen through
The steps from when the tweet button is clicked until the Twitter Web Intent window opens are roughly as follows.
- Client: Click the "Tweet" button
- Client: Send a request to the server
- Server: Upload an image to the Twitter server
- Server: Post a tweet with the image
- Server: Extract "pic.twitter.com/...", a URL of the image, from the response
- Server: Respond with the extracted URL
- Client: Open Twitter Web Intent with the URL
NOTE
- Twitter API version to be used is v1.1
- Uploading images is currently only possible with that version.
- Authentication is performed by a library of my own making.
- I couldn't find a maintained OAuth 1.0a (Authentication) library.