Channel Your Vision


With your query in mind, learn about the Twitter API

This task is about getting familiar with the Twitter Application Programming Interface, or API. Load up the Twitter API docs

If you have never used an API before, never fear. You'll notice that there's a lot of information that you need to sift through!  An API call is like a way to execute a function call on someone else's computer, in this case a server hosted by a large company. Reading the API docs is basically your ticket to understanding what function calls are allowed, how you need to format them, and what information they will return. 
 
Browse through the different "resources." Click through to the full descriptions of different resource calls. You'll notice that some require authentication, which is a topic we are not covering in this challenge. But several of the available API calls do not require authentication, including search!
 
A very cool thing about restful APIs (hint) is that they make use of the same protocol that your browser uses to display web pages: HTTP. As a result, what we described as a "function call" above is just a regular old URL. The upshot is that if you construct your API call and paste it into your URL bar, it will display the results right there in your browser! What better way to take the API for a casual test run?
 
Try out the unauthenticated user_timeline API call. Start out with this basic construct for the API call:
 
 

 

If you click on this link you should a JSON-formatted response in your browser. (You may want to stop and marvel at how cool it is that this is literally just a bunch of plain old text that Twitter's servers just sent you, and that you can use this important plumbing to build fantastic and wonderful web applications of untold complexity). Try adding different arguments to the url, as outlined in the docs. That's not too hard, eh? 

Answer these questions as you go. 

  1. What are some of the fields returned in the user_timeline API call? What are some of the different data types (eg. string, date, integer...) 

  2. What happens when you try to submit an API call that is broken? 

  3. A "path style" API call looks like example.com/api/username/search/search-term. An argument-style query uses argument strings such as example.com/api?person=username&search=search_term. How are Twitter's queries constructed? Can these formats be combined? Why might you use one versus the other in different circumstances? (Note that these questions are the subject of endless discussions amongst web developers. There is some well-known wisdom here but not necessarily a "right" answer, so treat these questions as fodder for discussion and raising new questions-- and don't spend TOO much time on it).  

  4. You will often hear people describe the Twitter (and other) APIs as "rest-ful." What makes something a "restful" API?  

Once you're done with these, you should feel comfortable formatting query parameters, submitting queries in your browser, and visually parsing long ugly blurbs of JSON text. Hooray! On to the next task. 

Diskutera uppgift


  • Matthew McKenna sa:

    Sadly when I clicked on the above link so see the example: https://api.twitter.com/1/statuses/user_timeline.json?screen_name=p2pu

     

    All that I was returned was an error. Which I'm used to when I try things myself but it's frustrating in courses.

     

     

    Currently trying to figure out how to use the new one, the documentation for which can be found at the link in the above error message..

    i 27 januari 2014 13:42
  • Ar sa:

    1. What are some of the fields returned in the user_timeline API call? What are some of the different data types (eg. string, date, integer...) 

    A: I answer this from API 1.1 documentation, here they are:

    • favorited: a boolean
    • truncated: a boolean
    • created at: a date
    • text: a string

    2. What happens when you try to submit an API call that is broken? 

    A: twitter give me error message and code

    3. A "path style" API call looks like example.com/api/username/search/search-term. An argument-style query uses argument strings such as example.com/api?person=username&search=search_term. How are Twitter's queries constructed? Can these formats be combined? Why might you use one versus the other in different circumstances? (Note that these questions are the subject of endless discussions amongst web developers. 

    A: twitter seems to use the argument style query. I don't knkow which is better used between the two

    4. You will often hear people describe the Twitter (and other) APIs as "rest-ful." What makes something a "restful" API?

    A: from wikipedia "A RESTful web API (also called a RESTful web service) is a web API implemented using HTTP and REST principles. It is a collection of resources, with four defined aspects:"

    i 27 november 2013 09:37
  • Richard sa:

    Clicking the link gives an error message as Twitter API is now v1.1. How to proceed with this?

     

    {"errors": [{"message": "The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.", "code": 68}]

    i 16 augusti 2013 18:11

    Lindsay sa:

    I also ran into this error.....

    i 25 september 2013 21:50 som svar på Richard
  • Eenvincible sa:

    Hello,

    I just put together an awesome blog post answering all the questions required by this challenge and I hope you guys check it out and let me what I think and remember to leave a link to yours if you have one! I am having so much fun!

    http://simpledeveloper.wordpress.com/2012/12/31/channel-your-vision-call-me-maybe-api/

    Thanks and see you around!

    i 31 december 2012 18:01
  • govindreddy sa:

    1.What are some of the fields returned in the user_timeline API call? What are some of the different data types (eg. string, date, integer...)
    collection of contributors,string,Array of strings,Boolean,int,objects
    2.What happens when you try to submit an API call that is broken?
    returns exception error with message with code number.
    3.A "path style" API call looks like example.com/api/username/search/search-term. An argument-style query uses argument strings such as example.com/api?person=username&search=search_term. How are Twitter's queries constructed? Can these formats be combined? Why might you use one versus the other in different circumstances? (Note that these questions are the subject of endless discussions amongst web developers. There is some well-known wisdom here but not necessarily a "right" answer, so treat these questions as fodder for discussion and raising new questions-- and don't spend TOO much time on it).
    Twitter's querries constructed  as argument-style querries.
    examples of querries constructions--
        ?q=Envato – Searches for tweets containing the string Envato
        ?q=#Envato – Searches for hashtags of Envato
        ?phrase=Envato+marketplace – Searches for tweets containing the phrase Envato marketplace
        ?q=from:NETTUTS – Returns all tweets from NETTUTS
        ?q=to:NETTUTS – Returns for all tweets to NETTUTS
    4.You will often hear people describe the Twitter (and other) APIs as "rest-ful." What makes something a "restful" API?  
    REST stands for Representational State Transfer It relies on a stateless, client-server, cacheable communications protocol --  the HTTP protocol is used.rather than using complex mechanisms such as CORBA, RPC or SOAP to connect between machines, simple HTTP is used to make calls between machines. The World Wide Web itself, based on HTTP, can be viewed as a REST-based architecture. RESTful applications use HTTP requests to post data (create and/or update), read data (e.g., make queries), and delete data. Thus, REST uses HTTP for all four CRUD (Create/Read/Update/Delete) operations.
    from-Learn REST: A Tutorial http://rest.elkstein.org/

    i 4 december 2012 23:57
  • Ollie sa:

     

    What are some of the fields returned in the user_timeline API call? What are some of the different data types (eg. string, date, integer...) 
     
    There's a lot of stuff! Individual tweet ID, if there's geolocation, if it's an @reply and to whom, the user, their number fo followers, location, profile background image...
     
    What happens when you try to submit an API call that is broken? 
     
    A JSON error object - message (sorry, that page does not exist), and code (34).
     
    A "path style" API call looks like example.com/api/username/search/search-term. An argument-style query uses argument strings such as example.com/api?person=username&search=search_term. How are Twitter's queries constructed? Can these formats be combined? Why might you use one versus the other in different circumstances? (Note that these questions are the subject of endless discussions amongst web developers. There is some well-known wisdom here but not necessarily a "right" answer, so treat these questions as fodder for discussion and raising new questions-- and don't spend TOO much time on it).
     
    Twitter seems to use a combination of the two since there's a path leading to specifically API functions and it then uses arguments to return the appropriate thing.
     
    Not so sure why you'd pick one over the other in different circumstances...
     
    You will often hear people describe the Twitter (and other) APIs as "rest-ful." What makes something a "restful" API?  
     
    So a RESTful API is one that conforms to the REST constraints (http://en.wikipedia.org/wiki/Representational_state_transfer#Constraints) and is based on a setup where the client sends a request to a server and the server processes and returns the appropriate response.
    i 23 november 2012 19:04

    Eenvincible sa:

    Hey thanks for the awesome answers you gave!!

    Please check out my blog post on the same and let us compare our progress!

    http://simpledeveloper.wordpress.com/2012/12/31/channel-your-vision-call-me-maybe-api/

    Thanks and hope to see you around!

    i 31 december 2012 18:03 som svar på Ollie
  • juancarloscruzd sa:

     

    1. What are some of the fields returned in the user_timeline API call? What are some of the different data types (eg. string, date, integer...) 

      • The fields returned by the query...are the tweets of the username, i've tested with my username...and it's amazing!
        The query returns all the information to build a good application...sometimes the information is repeated (usrename information)

    2. What happens when you try to submit an API call that is broken? 

      • The query return json...with two variables...one is an error message and other is the status of the query. 

    3. A "path style" API call looks like example.com/api/username/search/search-term. An argument-style query uses argument strings such as example.com/api?person=username&search=search_term. How are Twitter's queries constructed? Can these formats be combined? Why might you use one versus the other in different circumstances? (Note that these questions are the subject of endless discussions amongst web developers. There is some well-known wisdom here but not necessarily a "right" answer, so treat these questions as fodder for discussion and raising new questions-- and don't spend TOO much time on it).

      • The first path-style...is used for REST applications, each elemente has his own path...Twitter combined the two path-style...because the "Entity" is not the user, is the TIMELINE....this entity recieves a parameter (username)
    1. You will often hear people describe the Twitter (and other) APIs as "rest-ful." What makes something a "restful" API?  

      • The restful API is other way to delegate "functions" to the developers,,in this case there are note functions, are Entities that has atributes.

    i 26 augusti 2012 21:45

    Eenvincible sa:

    Nice work here mate! Are you still working on this challenge or you are already done? Do you have a blog? please share a link of it on my blog and let us connect!

    http://simpledeveloper.wordpress.com/2012/12/31/channel-your-vision-call-me-maybe-api/

    Thank you!

    i 31 december 2012 18:04 som svar på juancarloscruzd
  • Alvaro sa:

    I tried this call to get the last tweet from efenoticias:

    https://api.twitter.com/1/statuses/user_timeline.json?screen_name=efenoticias&count=1&include_rts=1 

    1. It returns an array of id:value pairs that makes up the information of the tweet. JSON only admits strings as id's and strings, numbers, arrays, booleans and null as valueI found a really nice explanation about diferences between Javascript Object Notation (JSON) and JavaScript Object Literal that may help.  http://www.returngis.net/2012/06/json-vs-javascript-object-literal/ (Sorry, the web is in spanish, but you may also know google translator ;))

    2. I get this error message: {"errors":[{"message":"Sorry, that page does not exist","code":34}]}

    3. I tried & and ; to separate the  and get the same result.

    4. This web explain it with a good sense of humour: http://tomayko.com/writings/rest-to-my-wife

    i 21 augusti 2012 17:01
  • José Santos sa:


    1.I made timeline api call but what i got in return was a json object which was unreadable sins it was optimizes for transferring speed.
    Sins I was anable to read ist clearly I used the  JSON Formatter & Validator from http://jsonformatter.curiousconcept.com/ to make the data object von the twitter api call more readeble.
    The result was wary readable, I got a well formatted json object.
    The data that I got back was quite extensive, I even use my twitter name jonocosa to get some personal data.
    To answer the question the data type I found were data objects, the also a lot of string and also some numbers.

    2.I got an erro messege.
    This one:
    {"errors":[{"message":"Sorry, that page does not exist","code":34}]}

    4.Basically what make a restful api is the use of more then just the get and post methods for data transferring.

    i 11 augusti 2012 17:13
  • misifus_mankhado sa:

     

    Since I'm not all familiar with all this stuff I just hit plain old Ctrl+V on the Url bar to se what happens.

    I've just got these so far.

    1. What are some of the fields returned in the user_timeline API call? What are some of the different data types (eg. string, date, integer...) 
      Some of the fields would be my own tweets' text listed after ,"text":" and it lists the date after ,"created_at":" . It has also his own strings I'm not at all familiar, such as "In_response_to": and the like.

    2. What happens when you try to submit an API call that is broken? 

      		This comes out:
      {"errors":[{"message":"Sorry, that page does not exist","code":34}]}
      
      
      
    i 16 juli 2012 02:21

    Jessy Kate Schingler sa:

    nice! i believe "In_response_to" is a unique identifier for the tweet that someone is replying to, if/when the tweet is a reply. so probably  that field would be empty if the tweet is not a reply! 

    i 16 juli 2012 04:58 som svar på misifus_mankhado
  • Alex sa:

    I started learning Python recently, first by taking a Udacity course, then by doing lots of reading online and experimenting on my computer. I decided to take this query, for the search term "curation", because curation is something I've been monitoring for many years, in my content analysis practise.

    http://search.twitter.com/search.json?q=curation

    Using the urllib2 and json modules in Python, I was able to play around a little with this query. It only showed about 15 or so latest results, so I added some parameters to get 100, which is the maximum. This time, though, I wanted to try the ATOM format:

    http://search.twitter.com/search.atom?q=curation&rpp=100

    With the minidom module in Python, I was able to manipulate this document. With urllib2, urls are a brease in Python. You just use the .urlopen function and then the .read() function. You can assign the document to a variable and then manipulate it.

    I'm still a beginner, so I didn't do anything crazy with the queries, but still I had a lot of fun. :)

    i 22 maj 2012 17:37

    Eenvincible sa:

    I was on Udacity too - the first group of students! I love it there. Nice to meet you.

    Please check out my blog at:

    http://www.simpledeveloper.wordpress.com

    Thanks and please stop by

    i 31 december 2012 17:21 som svar på Alex
  • Jessica Ledbetter sa:

    I went with the search api call and used Chrome dev tools to debug. I used jQuery to call and spit them out on a page. Neat!

    i 19 april 2012 15:03

    Saurav Foss sa:

    Cool, how'd you do that ?

    :)

    i 1 oktober 2012 07:02 som svar på Jessica Ledbetter
  • lunchtime sa:

    I've used Flash Builder for a Mobile App that pages the list of people your account is following, then gives you an option to remove follower en bulk

    i 18 april 2012 21:40
  • xzorzist sa:

    I used php to hold the connection to my user name and display my last tweet, along with the date and time.

    i 18 april 2012 03:54
  • rodrigo sa:

     

    I use my own twitter username and  is all there in a simple plain text :)
     
    https://api.twitter.com/1/statuses/user_timeline.json?screen_name=djroxx
     
    https://api.twitter.com/1/users/show.json?screen_name=djroxx&include_entities=true
     
     
    1) Tweets, retweets, user css, times and dates
    Sring date, string text, user verified
     
    2) {"error":"This method requires authentication.","request":"\/1\/statuses\/user_timeline.json?screenname=djroxx"}
     
    4) REST  Clients initiate requests to servers; servers process requests and return appropriate responses.
    i 8 april 2012 20:55
  • Anonym sa:

    i not really sure about the it but here what i thought . it show how the it link from verified the user id then load the background image 

    i 3 april 2012 09:53
  • Newman5 sa:

    Hey Gang,

    I recorded my general comments.  Kinda long at 4:45 but, it was fun for me to record.

     

    http://www.youtube.com/watch?v=JOa9Z6B5bMk

     

    cheers,

    n

    i 1 april 2012 16:44

    Jessy Kate Schingler sa:

    hey newman, 

    sorry for the delay in responding to this. very awesome screencast!! what software are you using?

    to respond to a couple of your comments in the video: i would consider the url "data type" to be a string, although in terms of validation, it could be validated to the more speciifc string format of a URL.  

     

    good coverage of the different ways to break the url. 
     
    re SOAP and REST - SOAP is a huge and very detailed, complicated standard, whereas generally RESTful APIs use HTTP and query arguments (GET)/ or data (POST). a SOAP API requires the user to build large, somewhat unweildy custom XML objects to submit to the server, which is more work for the user instead of just piggybacking on top of an http module in whatever language you are using. the SOAP standard is quite powerful, but sacrifices the simplicity of REST. (that is my somewhat biased perspective). 
     
    thanks for the comment... great stuff :)
    i 3 april 2012 20:50 som svar på Newman5
  • Philipp sa:

    I'm struggling with the error messages. I added a count parameter to the call (to limite the number of results returned and get the following error:

    {

    "error":"Rate limit exceeded. Clients may not make more than 150 requests per hour.","request":"\/1\/statuses\/user_timeline.json?screen_name=sharingnicely&count=10"

    }

    I definitely have not made more than 150 requests during the last hour. This is the browser URL I requested:

    https://api.twitter.com/1/statuses/user_timeline.json?screen_name=sharingnicely&count=10

    On the other hand, I might have come up with an idea for a project. Someone has registered a screen name that I would like to use. The person has not tweeted once and is clearly just name sqatting. I read that twitter releases inactive accounts occasionaly. I want to write a script that regularly (once a day or a couple times a day) checks if the account still exists and produce some kind of output if it has been deleted ... and I can go ahead and register it. 

    The way I understand REST (representational state transfer, wikipedia entry) it is meant allow transactions between different servers (like a web server), by different clients (like a web browser) with minimum coordination overhead. Each call from a client to the server assumes there has never been a call before and there is no stored data that describes the relationship between client and server. Is that correct?

    i 16 mars 2012 14:34

    Jessy Kate Schingler sa:

    cool, that's a great idea for a script, and i think you could do it from what you learn here.... with a different API call of course. (i have a feeling you might have already looked into it?)

    as for the error, i've run into that before when i was on a wireless router or behind a NAT - basically if you're on a big network sharing an external IP address, twitter might not be able to differentiate you from others on the network making API calls. i just tried your API call and it worked perfectly. maybe try it again? :)

    i 18 mars 2012 04:07 som svar på Philipp

    Jessy Kate Schingler sa:

    i like your API description too. i was actually trying to get at what differentiates RESTful APIs from other types of APIs (like SOAP or any kind of interface), but i realized from your answer that a) the conceptual definition of an API is equally (if not more) interesting to explore, and b) my intention is not at all obvious from the question :). 

    i 18 mars 2012 04:10 som svar på Philipp

    Newman5 sa:

    Hey Philip,

    You said: Each call from a client to the server assumes there has never been a call before and there is no stored data that describes the relationship between client and server. Is that correct?

    I say, I think you are right!  I'm thinking this 'no stored data' is the 'stateless contraint' of the REST ... framework? structure? Architecture.  REST is a software architecture using HTTP... I'm glad there are no mulitple choice tests on the P2PU.

    Here is the Stateless Contraint verbage from Wikipedia:

    The client–server communication is further constrained by no client context being stored on the server between requests.

     

     

    i 1 april 2012 16:42 som svar på Philipp

    Eenvincible sa:

    Your idea is pretty neat. It can be a lot of fun! I would like to know where you have reached with it so, please stop by my blog and let us connect. We could collaborate on cool apps if you are interested.

    http://simpledeveloper.wordpress.com/2012/12/31/channel-your-vision-call-me-maybe-api/

    Thanks again and see you soon!

    i 31 december 2012 18:08 som svar på Philipp