If you implement "Login With Twitter" for your website, users don't need to remember  password for your website, so users will feel comfortable to use your website. In advance, you can access users  timeline feed. Twitter is providing Twitter4J to implement twitter api using java, download this twitter4j and add it to build path

Project

I have provided sample project here, download it. Open Setup.java and give your twitter app credentials, database credentials. Create MySQL database schema with name "demos". Created below specified table. Import this project into Eclipse, add it to tomcat server, run index.html

Implementation

  1. When user click on Login with twitter button, Provide them access link which is generated by Twitter4j with your app credentials. 
  2. User will be redirected to twitter api page
  3. Once user gives permission, access token and oauth verifier will be sent to callback URL
  4. Now verify the access token with oauth verifier. It will generate access token object which will have access token and access token secret 
  5. Now save access token and access token secret in database with user details like twitter user id and screen name.
User cant change their twitter user id, so we can use this to identify user. If user login again, we can process user's account using twitter user id. Whenever you want to update status on user's timeline, you can do with these saved access tokens.

Create App In Twitter Developer Page

Open twitter apps webpage.  Create your app and get Consumer Key and Consumer Secret Key. Observe below diagram.

Database Table

Created database table like below.

CREATE TABLE `demos`.`twitter_user` (
  `user_id` INT NOT NULL AUTO_INCREMENT COMMENT '',
  `twitter_user_id` INT NULL COMMENT '',
  `screen_name` VARCHAR(45) NULL COMMENT '',
  `access_token` VARCHAR(100) NULL COMMENT '',
  `access_token_secret` VARCHAR(100) NULL COMMENT '',
  `created_date` DATETIME NULL DEFAULT CURRENT_TIMESTAMP COMMENT '',
  PRIMARY KEY (`user_id`)  COMMENT '',
  UNIQUE INDEX `twitter_user_id_UNIQUE` (`twitter_user_id` ASC)  COMMENT '');

Prepare Signin Link

Observe below code. Configure twitter object with Consumer Key and Secret Key, Generate request token with callback URL, save it to session. Generate authentication URL and redirect to that URL
// configure twitter api with consumer key and secret key
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
  .setOAuthConsumerKey(Setup.CONSUMER_KEY)
  .setOAuthConsumerSecret(Setup.CONSUMER_SECRET);
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
request.getSession().setAttribute("twitter", twitter);
try {
    
    // setup callback URL
    StringBuffer callbackURL = request.getRequestURL();
    int index = callbackURL.lastIndexOf("/");
    callbackURL.replace(index, callbackURL.length(), "").append("/callback");

    // get request object and save to session
    RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL.toString());
    request.getSession().setAttribute("requestToken", requestToken);
    
    // redirect to twitter authentication URL
    response.sendRedirect(requestToken.getAuthenticationURL());

} catch (TwitterException e) {
    throw new ServletException(e);
}

Callback Servlet

Callback servlet will receive oauth_verifier parameter. Verify access token with that verification code, then you will get access token object, Now save or update access token or access token secret to database. Here we identify user with twitter user id that is always constant. TwitterDAO.selectTwitterUser method gives user object based on twitter user id.
// Get twitter object from session
Twitter twitter = (Twitter) request.getSession().getAttribute("twitter");
//Get twitter request token object from session
RequestToken requestToken = (RequestToken) request.getSession().getAttribute("requestToken");
String verifier = request.getParameter("oauth_verifier");
try {
    // Get twitter access token object by verifying request token 
    AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, verifier);
    request.getSession().removeAttribute("requestToken");
    
    // Get user object from database with twitter user id
    UserPojo user = TwitterDAO.selectTwitterUser(accessToken.getUserId());
    if(user == null) {
       // if user is null, create new user with given twitter details 
       user = new UserPojo();
       user.setTwitter_user_id(accessToken.getUserId());
       user.setTwitter_screen_name(accessToken.getScreenName());
       user.setAccess_token(accessToken.getToken());
       user.setAccess_token_secret(accessToken.getTokenSecret());
       TwitterDAO.insertRow(user);
       user = TwitterDAO.selectTwitterUser(accessToken.getUserId());
    } else {
       // if user already there in database, update access token
       user.setAccess_token(accessToken.getToken());
       user.setAccess_token_secret(accessToken.getTokenSecret());
       TwitterDAO.updateAccessToken(user);
    }
    request.setAttribute("user", user);
} catch (TwitterException | DBException e) {
    throw new ServletException(e);
} 
request.getRequestDispatcher("/status.jsp").forward(request, response);

89 comments:

  1. how to implement login with twitter functionality in a web application using java play framework?

    ReplyDelete
  2. Thanks for this tutorial, it saved my project

    ReplyDelete
    Replies
    1. Can you send me your code to my email ID : "aruntheboss222@gmail.com", Am getting error. I need this code for my project, pls

      Delete
  3. To begin adequately first gathering the general population who really have something intriguing to state on TweetDeck buy twitter followers uk

    ReplyDelete
  4. When you set up your Twitter account, your first aim would be to get the maximum number of followers. BRSM.io

    ReplyDelete
  5. many people come and go but i don't think that anyone can replace him https://twitter.com/darrenwinters01 follow this man for the best ideas about business..!!

    ReplyDelete
  6. Adopt Restrictions on Posts, yet comprehend the necessities of the NLRA first! social media groups

    ReplyDelete
  7. I received all the services for which I paid, the price is affordable and corresponds to quality. I recommend ALL-SMM to all those who want to cheat Instagram account ... thanks to the guys for the great work! :))) Now I'm going to buy Instagram likes.

    ReplyDelete
  8. howdy was simply checking whether you minded a remark. i like your site and the thme you picked is super. I will be back. Buy Organic Twitter Retweets

    ReplyDelete
  9. Much thanks to you for some other useful blog.
    Twitter accounts for sale

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. Hey what a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you. Buy Twitter Likes

    ReplyDelete
  12. If you are a music lover I suggest you stay in Korca and listen to their beautiful serenades. Every note they sing seems like it is a part of a beautiful story from the city Albanian Riviera

    ReplyDelete
  13. More often than not, when a LinkedIn profile for the organization is available, it is appeared at the exceptionally top of a hunt. visit now

    ReplyDelete
  14. https://www.socifan.com/free-youtube-views It can be pretty harsh for beginners to see legends like PewDiePie and T-Series accumulate millions of views that easy. Don't fall into despair, though. It's time to go berserk with SociFan; we got your back with free YouTube views!

    YouTube is a platform with tight competition, and it can be extremely challenging for a beginner to grind amongst the best in the game. Nevertheless, all hope is not lost yet.

    This harsh competition is what makes YouTube beautiful and diverse. In this way, users have millions of unique content which is ready to consume. There is something for everyone.

    ReplyDelete
  15. So, when you decided to buy facebook likes you can benefit from many variations with our service.

    ReplyDelete
  16. Thanks for sharing this awesome guide about buy facebook followers, it is very helping for all. I recommend others to visit this website. Keep sharing.

    ReplyDelete
  17. This is such a nice post, I have been impressed by the unique content it has to offer thanks for sharing such nice and informative post buy bulk Instagram accounts

    ReplyDelete
  18. I like your content, it's so nice and unique, everybody likes unique content but your content is easy to understand for your readers too buy Facebook accounts

    ReplyDelete
  19. Thank you for sharing such nice and informative post, I have always lacked this talent of writing unique content, you are doing an excellent job, keep it up buy Twitter accounts

    ReplyDelete
  20. Thank you for nice post, I have been a fan of those who have this unique talent of writing unique content, keep up the good work buy YouTube accounts

    ReplyDelete
  21. I came across Google and found your blog, I think your blog deserves higher rating, what's the criteria google uses to rank sites buy Gmail accounts

    ReplyDelete
  22. I like your site so much and I have bookmarked this site to get updated, your content is fresh and breath of fresh air for avid readers buy Instagram accounts

    ReplyDelete
  23. Thank you for the nice post, how have you been able to produce unique content everytime, I guess this is an art and only few have it keep it up

    ReplyDelete
  24. You can purchase all of the social media like TikTok, YouTube, Instagram likes views, comments, followers, subscribers and so many greater from India's No.-1 promoting website https:www.ytviews.in/ with a money-back guarantee, steady method, genuine service, 24/7 help, and many more offers.

    ReplyDelete
  25. This site is great, I really appreciate how you put up the information.Buy YouTube Views

    ReplyDelete
  26. Benifit is a new virus that installs itself on your Yahoo accounts and pretends to be a legitimate antivirus program. The main feature of this scam is the ability to steal your passwords & email ids. This software is continually being sold for a very cheap price on the Internet, promising that it will protect your accounts from being hacked. After downloading this software onto your computer, it will then pretend to Buy yahoo accounts scan your system and tell you that your Yahoo accounts have been infected with some invisible virus which needs to be removed before it does any damage.

    ReplyDelete
  27. I am glad to read this article.I think this will useful and informative topic for everyone.This is such a nice post.I have been impressed by the unique content.I loved your post and got some good ideas for it. Pvainsta

    ReplyDelete
  28. CCleaner Pro Crack really is a useful utility for desktops with MS Windows. That cleans out all these junk that accumulates greater than time like damaged shortcuts, momentary files, and many other complications. It is the easiest tool for cleansing your machine. Mainly because it will make your system do the job smoothly and speedily. What's more, it secures your system and protects your privateness. It cleans your

    ReplyDelete
  29. I read this article. I think You put a great deal of exertion to make this article.

    We Provide High Quality Smm Service Buy Smm Services _ Checkout

    high quality smm service provider

    buy gmail accounts

    buy google voice numbers

    buy facebook likes

    ReplyDelete
  30. Ashampoo Burning Studio Crack is always better to use dedicated software instead of Windows to burn your files to CD, DVD, Blueray. One of the best tools in this area is Ashampoo Burning Studio. This software offers you the best and most effective solution to burn your data to discs. First, there is a software interface that meets the expectations of users with multiple designs. Many features of this software include burning data, backing up or restoring files, burning or converting music, repairing burned discs, and creating covers and labels. Ashampoo Burning Studio software uses a powerful burning engine to support all popular disc formats and has a fast burning process.

    ReplyDelete
  31. Best Bulk Email Accounts Provider Agency in the Market. Buy Email Accounts like Gmail, Yahoo, Outlook, and More at Affordable Prices.
    Buy Email Accounts
    Buy Gmail Accounts

    ReplyDelete
  32. This article was enjoyable to read. You're welcome! Your blog is bookmarked on my computer so I can check out your new posts when you publish them.
    buy YouTube real Views

    ReplyDelete
  33. Hi,

    Hope you are doing fine!

    My name is Haseeb, I work for an online marketing agency.

    I came across your site (http://blog.sodhanalibrary.com/) today and got impressed with the regular updates on it.

    Just wanted to know if you do accept guest posts on your site Also, if you could let me know the price per in-content text link placement on an existing blog post of your site?

    Looking forward to hearing from you soon.

    Regards,
    Haseeb

    ReplyDelete
  34. Game Killer Apk Mod programming could possibly get an alternative choice to hack games and moreover anything which you will need. This product should be used on established android telephones. You’re able to employ disconnected online games using the help of this product https://kingsoftz.com/game-killer-apk-full-crack/

    ReplyDelete
  35. This is an excellent post that you shared with us, and the blog is impressing more people to read it. Best site to buy YouTube Views

    ReplyDelete
  36. This is an informative blog. If you are Looking for Plumber that will improve your Home. Feel free to visit Wills Plumbing Adelaide to know more about our services. Instagram pva accounts

    ReplyDelete
  37. I am very impressed with your post because this post is very beneficial for me and provide a new knowledge to me

    TransMac Crack
    Apowersoft ApowerManager Crack
    Zemana AntiLogger Crack

    ReplyDelete
  38. Social media marketing is currently the most important way to express your business to your customers. Due to recent pandemic situation, the world has changed digitally, for this purpose social media accounts are really necessary. And we recommend you to buy Facebook, Instagram, Twitter Pinterest Google accounts from us at very affordable and reasonable price. Thanks!buy instagram pva accounts

    ReplyDelete
  39. شكرا لمشاركتك. انها وظيفة مفيدة جدا بالنسبة لنا. يمكنك أيضًا زيارة تعرف أهم الفيتامينات لتقوية الأعصاب والعضلات في 7 أيام | صدى القاهرة لمزيد من المعلومات المتعلقة بشركة فيكتور ستيل. أود أن أشكرك على مشاركة هذه المقالة هنا.

    ReplyDelete
  40. I guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues. I do not know how to Crack But Thankfully, I recently visited a website named Cracked Fine
    CCleaner Pro Crack
    Office Timeline Crack
    Cyberghost vpn Crack

    ReplyDelete

  41. Thanks for Sharing such an amazing article. Keep working... Your Site is very nice, and it's very helping us.. this post is unique and interesting, thank you for sharing this awesome information Avast Pro Antivirus Crac

    ReplyDelete
  42. Vantage point X is First Artificial Intelligence Empowered trading system, which trades on your MT4/MT5 platform on your behalf, giving best possible results and Highest accuracy of Upto 89%.
    drawdown.vantage pointx

    ReplyDelete
  43. I like your all post. You have done really good work. Thank you for the information you provide, it helped me a lot. crackroom.org
    Download Crack PC Softwares
    CCleaner Pro Crack

    ReplyDelete
  44. Yahoo is best and popular email platform after Gmail, you should buy yahoo pva Accounts to grow your digital marketing, you should Buy Yahoo PVA Accounts right now.

    ReplyDelete
  45. Thanks for sharing such an amazing post. Great Work. Love visiting your blog. I would like to thank you for sharing this post. Really Happy to Read. DVDFab Crack

    ReplyDelete
  46. I guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues. I do not know how to Crack Softwares Free Download But thankfully, I recently visited a website named crackedfine
    CCleaner Pro Crack

    ReplyDelete
  47. Thanks for sharing such an amazing blog with us it was full of informative data...... https://web.facebook.com/profile.php?id=100077029969298

    ReplyDelete
  48. Nice Post. I enjoyed Reading Your Article. It was very helpful.
    หวยออนไลน์

    ReplyDelete
  49. we are providing high quality pva Accounts with affordable price with replacement warranty you can also Buy Instagram PVA Accounts

    ReplyDelete
  50. I like your all post. You have done really good work. Thank you for the information you provide, it helped me a lot.I hope to have many more entries or so from you.
    Very interesting blog.
    aspc4u.com
    Avast Pro Antivirus Crack
    EZ CD Audio Converter Crack

    ReplyDelete
  51. I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business. Buy instagram pva accounts

    ReplyDelete
  52. I want you to thank for your time of this wonderful read!!! I definately enjoy every little bit of it and I have you bookmarked to check out new stuff of your blog a must read blog! 스포츠토토

    ReplyDelete
  53. Writing this type of article is one of the most important things you will ever learn. This is the type of article you will use to build your reputation as an author and also one that will help you get started in a career that is very profitable. Many people will ask me what I consider to be the most important part of this type of article. The answer is simple, the title. You need to create a quality title for your article before submitting it for publication.
    Buy google voice accounts

    ReplyDelete
  54. Your blog is so amazing and informative. This was an excellent article. Thank You for sharing it.
    Davinci Resolve Studio Crack

    ReplyDelete
  55. CCleaner pro crack is one of the wonderful software that is most commonly used all over the world in orderto remove unnecessary data and other harmful junk files to clean our computer from virus attack
    https://newcrackkey.com/ccleaner-pro-crack/

    ReplyDelete
  56. I like your all post. You have done really good work. Thank you for the information you provide, it helped me a lot. I hope to have many more entries or so from you.
    Very interesting blog.
    Crackplus.org
    Adobe Acrobat Pro DC Crack
    Outlook Recovery ToolBox Crack
    Avast Antivirus Crack
    Adobe Premiere Pro Crack
    DVDFab Crack

    ReplyDelete
  57. Excellent knowledge, You are providing important knowledge. It is really helpful and factual information for us and everyone to increase knowledge. Continue sharing your data. Thank you. Read more info about Buy Google voice accounts

    ReplyDelete
  58. to boost your social media marketing we suggest you to Buy Instagram PVA Accounts

    ReplyDelete
  59. I am really impressed with your work which content.
    IBeesoft Data Recovery Crack

    ReplyDelete
  60. Thanks to the person who owns this website, I learned a lot about what I need to know.https://crackdue.com/letasoft-sound-booster-1-11-0-514-crack-activation-key-keygen-2020/

    ReplyDelete
  61. This article appeals to me. Don't worry, I'll forward this to the right individuals in our company, and we'll see what we can do about include it in a future version.Click here

    ReplyDelete
  62. Amazing blog with fully loaded information . All the content is very good. Keep sharing like this. Buy Bulk Gmail Accounts

    ReplyDelete
  63. Very interesting post . Well written article. Keep sharing like this.Buy Bulk Gmail Accounts

    ReplyDelete
  64. If you are looking to Buy bulk Gmail accounts. This is the best place to Bulk Gmail Accounts. In our shops all types of google accounts and social media accounts available All are USA based accounts. we are given instant delivery. Buy Bulk Gmail Accounts

    ReplyDelete
  65. This comment has been removed by the author.

    ReplyDelete
  66. Buy Google Reviews will help you to boosting your business. If you want to increase your business then this the right place.We are actually focusing on providing a high-quality Google review with very reasonable price. Please visit our website :
    http://www.bulkgmailaccounts.com/buy-google-reviews/

    ReplyDelete
  67. If you want to establish in your bussiness in social media marketing gmail store is the best option.we provide single or bulk gmail accounts.
    Gmail store

    ReplyDelete
  68. Buy old Gmail Accounts
    - 100% Verified Faster Delivery
    We can’t do business or take other services online if we don’t have an email account Get Gmail PVA accounts and meet your needs for more productivit

    ReplyDelete
  69. I want you to thank for your time of this wonderful read!!! I definately enjoy every little bit of it and I have you bookmarked to check out new stuff of your blog a must read blog경주출장아로마
    완도출장아로마
    경기출장샵
    양평출장샵
    광명출장샵
    동두천출장샵

    ReplyDelete
  70. Good work done by your self .. i really appreciate your work and effort on this content. i hope that you will continue this effort.
    CCLEANER PROFESSIONAL CRACK

    ReplyDelete
  71. carbrand.net This is a compilation of all car brands, a comprehensive list of names and logos for all car companies worldwide. In this article, you will find the most popular automakers from every single country, other active auto manufacturers and even the non active car makes by each country.

    ReplyDelete
  72. This is a one of the best informetive website ,thereis a lot of information about food flower agricultiral and other's

    https://topperone.com/

    ReplyDelete
  73. And i’m glad reading your article. I think this is one of the most significant information for me. Really happy to find this. Buy Bulk Gmail Accounts

    ReplyDelete
  74. microsoft office 2016 crack
    Microsoft Office 2016 is type of MS Office which help the users to write, modify and present the document.

    ReplyDelete
  75. Thanks for sharing such a article. Its helpful for everyone. Keep blogging like this
    "buy telegram auto views
    "

    ReplyDelete
  76. buy tinder accounts with standard price. 100% workable tinder account. Fully satisfied. Verified account. Backup available.

    ReplyDelete
  77. Really so much informative post, that I want to see. Again thanks for this post.

    ReplyDelete
  78. Thanks for your significant post about the topic.If people want to buy SMM, SEO, reviews account services visit our website buy-google-play-store-reviews and contact fast

    ReplyDelete
  79. Followers Buzz delivers an impressive boost in social media followers buy with authentic engagement, offering a reliable solution for enhancing your online presence effortlessly

    ReplyDelete

Blogroll

Popular Posts