Import Twitter Search

Posted by agiletortoise, Last update 11 months ago

NOTE: This action no longer functions due to policy changes at Twitter that are out of our control. Visit the Twitter integration guide for details.

Prompt for a Twitter search query. Can be for any text string and supports the same syntax used in Twitter web search.

Use Twitter API to get a list of tweets matching the search and import them into a new draft as a Markdown list, with screen name and link to the tweet included.

Posted as an example of Twitter API use in Drafts.


  • script

    // set identifier for Twitter credentials you wish to use
    const twitterIdentifier = "";
    let q = "";
    let p = Prompt.create();
    p.title = "Twitter Search";
    p.message = "Entry search text below. Results will be imported into new draft in Markdown list format.";
    p.addTextField("q", "Query", q);
    if (! {
    else {
    	q = p.fieldValues["q"];
  • script

    // a few base values
    const apiURL = "";
    let f = () => {
    	let twitter = Twitter.create(twitterIdentifier);
    	let content = [`### Twitter Search: ${q}`,""];
    	let params = {
    		"q": q
    	let response = twitter.request({
    		"url": apiURL,
    		"method": "GET",
    		"parameters": params
    	if (response.statusCode == 200 || response.statusCode == 201) {
    		let tweets = response.responseData.statuses;
    		if (!tweets || tweets.length == 0) {
    			alert("No tweets found.");
    		for (let tweet of tweets) {
    			let id = tweet.id_str;
    			let sn = tweet.user.screen_name;
    			let tweetURL = `${sn}/status/${id}`;
    			let text = tweet.text; 
    			content.push(`- **@${sn}**: ${text} [link](${tweetURL})`);
    		let d = Draft.create();
    		d.content = content.join("\n");
    		console.log("Twitter search imported");
    	else {
    		console.log("Error: " + response.error);;


  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.