How to use Ruby on Rails to write Twitter

Source: Internet
Author: User
Tags ruby on rails

 

 

Ruby on Rails Twitter ApplicationProgramThe interface is very simple.Twitter is a simple rails application.The application interface for querying information is called as a GET request, while the application interface for modifying, creating, or deleting information is a POST request. The command itself is the URL read by your program. Twitter will respond in HTTPCodeAnd the data in the selected format.

Curl

To use the Twitter application interface, the curl tool is used. This tool is very simple. It can help you complete HTTP queries and check the results from the command line. It can be used on almost all platforms, so there should be no installation or use difficulties.

The only concern about converting to curl is the following:

-U Username: Password -- used to verify your identity before making a request.

-I -- put the HTTP header in the response. You may need to check the HTTP header returned by Twitter, especially the response code.

-W' \ n % {response_code} \ n' -- provides the response code behind the response. If you only want to respond to the Code, it is easier than-I conversion.

-D Var = Data & var2 = data -- send post data to publish messages. If the conversion exists, a POST request is generated; otherwise, a GET request is generated.

Verify

Most Twitter application interface commands require verification so that Twitter knows who sent the request. The Twitter application interface does not require cookies, so Twitter does not remember the person who sent the request. Before sending a request, you must verify the user name and password.

This is done by using the curl converted by-U. If my user name is aboutruby and the password is pass123, I will add the-u aboutruby: pass123 to my curl command.

Your friend's timeline

Perhaps the most common behavior on Twitter is to require your friend's timeline. This will happen when you log on to Twitter. Accessing this is like accessing http://twitter.com/statuses/friends_timeline.xml. Pay attention to the. xml following this URL. You can use .rssor. html to obtain this network type.

The following curl command line will execute this command. You should look at the XML output. We also need to perform more in-depth checks when parsing XML output.

$ Curl-u aboutruby: pass123

Http://twitter.com/statuses/friends_timeline.xml

PostArticle

Of course, the most common behavior on Twitter is to post or update an article. The curl command line has some minor differences. -D conversion is used to execute POST requests rather than get requests for HTTP behaviors and add data to published articles. The URL for this operation is a http://twitter.com/statuses/update.xml and may become a status value in the post parameter.

$ Curl-u aboutruby: pass123-d

'Status = posted from curl'

Http://twitter.com/statuses/update.xml

The remaining Twitter commands follow the same pattern. For a complete reference of Twitter commands, see the rest application interface document of VIKE on the Twitter application interface. It is worth mentioning that the Twitter application interface is free for everyone.

 

Http://twitter.rubyforge.org/

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.