Saving Tweet from Tweetbot to Draft

Hi,

Probably an extremely basic question: when I am saving a Tweet from Tweetbot, either using “Drafts Quick Capture” or directly the Draft icon in the Share Sheet on iOS, I get a Twitter URL in my Draft. How would I go to convert that Twitter URL in the content of the Tweet using a Draft Action (I presume) so that I can further exploit it from there…

Thanks,

I created an action for you that when run will replace a selected Twitter URL with the content of the tweet it refers to. You can expand on the action to find the first Twitter URL in a draft (or all), or assume it is the whole draft, etc. But I figured procesing the current selection would give you the safest starting point.

FWIW, I also included a line in the script to save a version, so you can always revert to the previous version if you get an unintended update.

Hope that helps.

1 Like

Thanks! I was looking for this too and got an API Call Error:999 when trying to run this action on a draft that contained a link to a tweet. Is there any additional input that is required?

Did you select the Twitter URL or just run the action on the draft?

I did try with the twitter url in the draft selected like below:

Update:
The action runs if I remove the extra text (?s=…) from the URL
I want to run this automatically on a draft that contains only one tweet link followed by another action that puts the content elsewhere. Is there a way to run the action without selecting the text?

The old Twitter API obviously doesn’t seem to deal with URL parameters. It should be simple enough to just take the non-parameter part (split by “?”, and take only the first section).

Only by extending it as per my original note:

The aim with the action was just taking the most basic case, but to provide the foundation for anyone who wanted to talk it further - as it seems you do.

1 Like

The action seems to cut off tweets beyond a certain length. I wonder if it has to do with the older tweet character limitation

I just had a look an that does seem to match with the example in the API documentation for getting a Tweet - a contraction of the content and inclusion of an ellipsis and a URL.

{
  "created_at": "Wed Oct 10 20:19:24 +0000 2018",
  "id": 1050118621198921728,
  "id_str": "1050118621198921728",
  "text": "To make room for more expression, we will now count all emojis as equal—including those with gender‍‍‍ and skin t… https://t.co/MkGjXf9aXm",
  "truncated": true,

This also occurs in [the Tweet data dictionary](https://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/object-model/tweet), where the same example is used.

In neither location does it seem to actually provide any further details about how the value is generated other than to say that it is:

The actual UTF-8 text of the status update.

… which is false based on the discrepancy between the post and the return.

Obscure Twitter API stuff here…they sort of piggybacked support for longer tweets onto the API after upping the character limit to 280. If you want the full text of a tweet (in this and other endpoints), you have to add the tweet_mode=extended parameter to your calls…and, in the result, use the full_text value, not the text value. Here’s a modified version of your getTweet function that should work to get the full text:

// Twitter API (v1.1) call to get content of a Tweet by ID
function getTweet(p_strID)
{
	let objTwitter = Twitter.create();
	let url = `https://api.twitter.com/1.1/statuses/show.json?id=${p_strID}&tweet_mode=extended`
	alert(url)
	let objResponse = objTwitter.request({
		"url": url, 
		"method": "GET"
	});
	if (objResponse.statusCode == 200) return objResponse.responseData.full_text;
	else
	{
		console.log("Twitter API Call Error: " + objResponse.statusCode.toString());
		console.log(objResponse.lastError)
		context.fail("");
		return;
	}
}
2 Likes