Confused about the Twitter API Project

Hey Everyone,

I was working through the Random Quote project and I took a look at the code for a few users who already did the project. Using a tutorial I can easily create a webpage with a button that will generate random quotes from an array I created in the .js file. I wanted to then start adding some of the Twitter API functionality, but I noticed when I am looking at other people’s code, it doesn’t seem to match mine at all. For example, I have the following in my .js file.

console.log('The bot is starting');
var Twit = require('twit');

var T = new Twit({
  consumer_key:         '1VgAIE9NyzA8svHnCRpabX44V',
  consumer_secret:      'VXVvmfBGCjSLXIiPs8Z6jWrZ4fz2rgMbpxaKe7tMksLYSwcYwp',
  access_token:         '857362421156937728-EfaOOXeFX96kTN02YTmP2dLtkZWNP0I',
  access_token_secret:  'YbKSazGcNCesfAQBTM9Ou1myaZeORMQhd9m9NV8xsV7nc',

T.get('search/tweets', { q: 'banana since:2011-07-11', count: 100 }, function(err, data, response) {

I don’t see anything that even looks like this in other solutions. I am pretty sure with this .js file it should get tweets that reference bananas and then print out the data. I created an NPM account and then downloaded twit and tried to use the provided documentation.Is anybody else trying to do the project like this?


I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

And you really really don’t want to put your consumer key and secret out like that.

The project isn’t necessarily about using the Twitter API. You just need to be able to tweet the quote, for that you just need to create a link. I did it like this:

To get the quotes you don’t have to use the Twitter API, although I guess you could. I used an API from mashape to get the quotes.

1 Like

Thanks so much guys. Yeah, it appears that other people didn’t bother to do it that way which was what was confusing me. I think if I did it this way, I would be better off reading a Twitter Bot tutorial. Thanks again!

I don’t think most of us had any idea how to use npm at that point in the curriculum. FreeCodeCamp doesn’t teach it until the Back End curriculum, at least.