Building a Web Twitter client that supports OAuth
Before reading this article, you should understand that OAuth provides a better way for the consumer site to access protected resources stored on the service provider's users. Because of the use of OAuth, user credentials will never be leaked to sites other than those with user data. With the development of the desktop Twitter client in part 1th, you can update Twitter status after granting Myttdesktopclient access to the data stored on Twitter. If you go back to Twitter, you get a better user experience because Access tokens can be reused.
This article shows you how to use OAuth to develop a Web Twitter client. The goal is to provide a WEB application that supports users to authenticate and update their status through OAuth. It can also display a friend's timeline. The application is the foundation of an excellent mashup site.
Development of Twitter Web client
Like Myttdesktopclient, the Web Twitter client will support users to update their Twitter status. In addition, it displays the latest status of the user and supports their deletion of their status. The WEB application also supports you in setting the callback URL, which will be redirected to this URL after successful OAuth authentication. This is useful for development purposes because we can redirect the browser to localhost. You will also notice that registering this application as a Browser application and registering it as a desktop application is slightly different OAuth authentication.
Sign up for your WEB application on Twitter-myttwebclient
Again, before you use OAuth on Twitter, you need to register your WEB application in http://twitter.com/oauth_clients. Or, if you prefer, you can modify applications that have been registered for the desktop Twitter client. I will register a new application on Twitter in the following ways.
Application Name:myttwebclient
Description: Using the OAuth Web Twitter Client
Application Web site: Enter your application home page here
Application Type:browser-We will develop a WEB application
Callback URL: The callback url,localhost to enter your application here will not work
Default Access Type:read & Write-we want to grant user write access
Using Twitter for Login:yes-we're not going to use Twitter to authenticate
Note that, unlike part 1th, this application type is Browser rather than Client. Also, remember to grant Read & Write permission and select the Yes, user Twitter for login check box.
Once you have successfully registered your application, you will get a user key, a consumer secret, and 3 URLs (Request token URL, access token URL, and authorization URL). The user key and the user secret are set in Web-inf/web.xml.
Develop and test myttwebclient
If you do not want to read the code, but you want to compile and run the Web application directly, you should set your own user key and user secret in Web.xml. Add the following library files under Web-inf/lib:
commons-logging-1.1.1.jar
log4j-1.2.15.jar
twitter4j-2.0.9.jar