Deno.js Twitter API Tutorial to Load Tweets of User in Browser Using TypeScript Full Project For Beginners

 

 

example.ts

 

 

import { TwitterApi } from './mod.ts';
import { keys } from './keys.ts';

// See correct format for keys in twitterApi.ts
let twitterApi = new TwitterApi(keys);
let twitterApi2 = new TwitterApi(keys, {apiVersion: '2'});

let userTimeline = await twitterApi.get("statuses/user_timeline.json", {
  user_id: "19025957",
  screen_name: "TTCnotices",
  count: "20",
  trim_user: "true",
  tweet_mode: "extended", // Used to prevent truncating tweets
});

console.log(await userTimeline.json());

let alternativeGet = await twitterApi.request("GET", "statuses/user_timeline.json", {
  user_id: "19025957",
  screen_name: "TTCnotices",
  count: "20",
  trim_user: "true",
  tweet_mode: "extended", // Used to prevent truncating tweets
});

// These post requests do not work in the current state and are here
// to show how someone would be able to use the post function
let postResult = await twitterApi.post("statuses/update.json", {
  status: "Hello Ladies + Gentlement, a signed OAuth request!"
});

let alternativePost = await twitterApi.request("POST", "statuses/update.json", {
  status: "Hello Ladies + Gentlement, a signed OAuth request!"
});

const tweetInfo = (await (await twitterApi2.get('tweets/1320822556614676480', {
  'tweet.fields': 'referenced_tweets',
  'user.fields': 'username'
})).json());
console.log(data);

 

 

Response

[
  {
    created_at: "Mon May 18 02:07:34 +0000 2020",
    id: 1262203141157720000,
    id_str: "1262203141157720068",
    full_text: "Line 1 Yonge-University: Regular service has resumed southbound at St Andrew.\nhttps://t.co/464apkmgj...",
    truncated: false,
    display_text_range: [ 0, 101 ],
    entities: { hashtags: [Array], symbols: [Array], user_mentions: [Array], urls: [Array] },
    source: "<a href=\"https://www.hootsuite.com\" rel=\"nofollow\">Hootsuite Inc.</a>",
    in_reply_to_status_id: null,
    in_reply_to_status_id_str: null,
    in_reply_to_user_id: null,
    in_reply_to_user_id_str: null,
    in_reply_to_screen_name: null,
    user: { id: 19025957, id_str: "19025957" },
    geo: null,
    coordinates: null,
    place: null,
    contributors: null,
    is_quote_status: true,
    quoted_status_id: 1262202517313724400,
    quoted_status_id_str: "1262202517313724417",
    quoted_status_permalink: {
    url: "https://t.co/464apkmgjr",
    expanded: "https://twitter.com/TTCnotices/status/1262202517313724417",
    display: "twitter.com/TTCnotices/sta…"
    },
    quoted_status: {
    created_at: "Mon May 18 02:05:05 +0000 2020",
    id: 1262202517313724400,
    id_str: "1262202517313724417",
    full_text: "Line 1 Yonge-University: Delays of up to 15 minutes southbound near St Andrew while we respond to an...",
    truncated: false,
    display_text_range: [Array],
    entities: [Object],
    source: "<a href=\"https://www.hootsuite.com\" rel=\"nofollow\">Hootsuite Inc.</a>",
    in_reply_to_status_id: null,
    in_reply_to_status_id_str: null,
    in_reply_to_user_id: null,
    in_reply_to_user_id_str: null,
    in_reply_to_screen_name: null,
    user: [Object],
    geo: null,
    coordinates: null,
    place: null,
    contributors: null,
    is_quote_status: false,
    retweet_count: 2,
    favorite_count: 2,
    favorited: false,
    retweeted: false,
    lang: "en"
    },
    retweet_count: 2,
    favorite_count: 0,
    favorited: false,
    retweeted: false,
    possibly_sensitive: false,
    lang: "en"
  },
  ...
]

Leave a Reply