skip to Main Content

How in the world do I use the Twitter API? Everything online seems outdated and doesn’t work. I created a twitter application on the developer portal and got my access tokens, etc. What do I do now? I’m trying to use JQuery to make an ajax get request. But what do I do the request on? Their documentation is complete trash.

3

Answers


  1. Please refer to the documentation

    Where it suggests that you can use the url

    https://api.twitter.com/1.1/search/tweets.json?q=%23superbowl&result_type=recent
    

    to get recent tweets with the superbowl hashtag.

    Note that the # in that url has been encoded to %23. You can find a reference for those encodings here.

    From the docs, these are the different search operations you can perform:

    Operator                            Finds Tweets...
    watching now                        containing both “watching” and “now”. This is the default operator.
    “happy hour”                        containing the exact phrase “happy hour”.
    love OR hate                        containing either “love” or “hate” (or both).
    beer -root                          containing “beer” but not “root”.
    #haiku                              containing the hashtag “haiku”.
    from:interior                       sent from Twitter account “interior”.
    list:NASA/astronauts-in-space-now   sent from a Twitter account in the NASA list astronauts-in-space-now
    to:NASA                             a Tweet authored in reply to Twitter account “NASA”.
    @NASA                               mentioning Twitter account “NASA”.
    politics filter:safe                containing “politics” with Tweets marked as potentially sensitive removed.
    puppy filter:media                  containing “puppy” and an image or video.
    puppy -filter:retweets              containing “puppy”, filtering out retweets
    puppy filter:native_video           containing “puppy” and an uploaded video, Amplify video, Periscope, or Vine.
    puppy filter:periscope              containing “puppy” and a Periscope video URL.
    puppy filter:vine                   containing “puppy” and a Vine.
    puppy filter:images                 containing “puppy” and links identified as photos, including third parties such as Instagram.
    puppy filter:twimg                  containing “puppy” and a pic.twitter.com link representing one or more photos.
    hilarious filter:links              containing “hilarious” and linking to URL.
    puppy url:amazon                    containing “puppy” and a URL with the word “amazon” anywhere within it.
    superhero since:2015-12-21          containing “superhero” and sent since date “2015-12-21” (year-month-day).
    puppy until:2015-12-21              containing “puppy” and sent before the date “2015-12-21”.
    movie -scary :)                     containing “movie”, but not “scary”, and with a positive attitude.
    flight :(                           containing “flight” and with a negative attitude.
    traffic ?                           containing “traffic” and asking a question.
    
    Login or Signup to reply.
  2. Since the new Twitter API requires authentication for all calls, even those not specific to a given account, it makes it very difficult to make calls to the API directly from Javascript.

    However, you can use TweetJS.com which offers a Javascript wrapper on the Twitter API, that does not require authentication. A hashtag search would be as follows;

    TweetJs.Search("#Music",
    function (data) {
        console.log(data);
    });
    
    Login or Signup to reply.
  3. I’ve posted a very simple example to github that should show how to interact with twitters api. This uses the Twitter api ,with documentation at https://www.npmjs.com/package/twitter.

    My project uses NodeJS and express to make the API call, and dotenv to access the hidden key variables in a config file. heres the repo below. https://github.com/scottmilla/Node-Twitter-Starter

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search