SlideShare a Scribd company logo
Linked Data &
Semantic Web
Technology




  Development of
Twitter Applications

                Part 3. OAuth

                Dr. Myungjin Lee
Twitter4J
    • What is Twitter4J?
             – an unofficial Java library for the Twitter API
             – easily to integrate your Java application with the
               Twitter service
             – http://twitter4j.org/en/index.html


    • Features
             – 100% Pure Java - works on any Java Platform version
               5 or later
             – Android platform and Google App Engine ready
             – Zero dependency : No additional jars required
             – Built-in OAuth support
             – Out-of-the-box gzip support
             – 100% Twitter API 1.1 compatible


    • API Support matrix
             – http://twitter4j.org/en/api-support.html




                                                                     2
Linked Data & Semantic Web Technology
OAuth
    • What is OAuth?
             – an open standard for authorization
             – a method for clients to access server resources on
               behalf of a resource owner
             – a process for end-users to authorize third-party access
               to their server resources without sharing their
               credentials


    • Twitter’s OAuth
             – OAuth v1.0a to provide authorized access to Twitter
               API
             – using HMAC-SHA1 signature




                                                                         3
Linked Data & Semantic Web Technology
OAuth Process for Desktop Application




                                            4
Linked Data & Semantic Web Technology
Registering Your Application
    • https://dev.twitter.com/apps/new


    your application name
                                         your application description




                                         your application’s publicly
                                         accessible home page

  webpage URL where twitter returns
  after successfully authenticating




Linked Data & Semantic Web Technology
Registering Your Application




                                  Consumer Key and Secret to get user’s Access Token




                                                                                       6
Linked Data & Semantic Web Technology
Application type
    • Read only
             – Read Tweets from your timeline.
             – See who you follow.


    • Read and Write
             –     Read Tweets from your timeline.
             –     See who you follow, and follow new people.
             –     Update your profile.
             –     Post Tweets for you.


    • Read, Write and Access direct messages
             –     Read Tweets from your timeline.
             –     See who you follow, and follow new people.
             –     Update your profile.
             –     Post Tweets for you.
             –     Access your direct messages.




                                                                7
Linked Data & Semantic Web Technology
Primary Classes and Interfaces of Twitter4J

    • TwitterFactory Class
             – A factory class for Twitter


    • Twitter Interface
             – basic interface to use all of APIs


    • AccessToken Class
             – Representing authorized Access Token which is
               passed to the service provider in order to access
               protected resources




                                                                   8
Linked Data & Semantic Web Technology
Getting Access Token
    1.       // The factory instance is re-useable and thread safe.
    2.       Twitter twitter = TwitterFactory.getSingleton();
    3.       twitter.setOAuthConsumer("[consumer key]", "[consumer secret]");
    4.       RequestToken requestToken = null;
    5.       try {
    6.         requestToken = twitter.getOAuthRequestToken();
    7.       } catch (TwitterException e) {
    8.         // TODO Auto-generated catch block
    9.         e.printStackTrace();
    10.      }
    11.      AccessToken accessToken = null;
    12.      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    13.      while (null == accessToken) {
    14.        System.out.println("Open the following URL and grant access to your account:");
    15.        System.out.println(requestToken.getAuthorizationURL());
    16.        System.out.print("Enter the PIN(if aviailable) or just hit enter.[PIN]:");
    17.        String pin = new String();
    18.        try {
    19.            pin = br.readLine();
    20.        } catch (IOException e) {
    21.            // TODO Auto-generated catch block
    22.            e.printStackTrace();
    23.        }
    24.        try {
    25.            if (pin.length() > 0) {
    26.                accessToken = twitter.getOAuthAccessToken(requestToken, pin);
    27.            } else {
    28.                accessToken = twitter.getOAuthAccessToken();
    29.            }
    30.        } catch (TwitterException te) {
    31.            if (401 == te.getStatusCode()) {
    32.                System.out.println("Unable to get the access token.");
    33.            } else {
    34.                te.printStackTrace();
    35.            }
    36.        }
    37.      }
    38.      // persist to the accessToken for future reference.
    39.      try {
    40.        storeAccessToken(twitter.verifyCredentials().getId(), accessToken);
    41.      } catch (TwitterException e) {
    42.        // TODO Auto-generated catch block
    43.        e.printStackTrace();
    44.      }




                                                                                                 9
Linked Data & Semantic Web Technology
Getting Access Token
    1.       private static void storeAccessToken(long useId, AccessToken accessToken) {
    2.          // store accessToken.getToken() and accessToken.getTokenSecret()
    3.          System.out.println("User ID: " + useId);
    4.          System.out.println("Access Token: " + accessToken.getToken());
    5.          System.out.println("Access Token Secret: "
    6.                                       + accessToken.getTokenSecret());
    7.       }

    8.       public static AccessToken loadAccessToken() {
    9.          String token = "[access token]";
    10.         String tokenSecret = "[access token secret]";
    11.         return new AccessToken(token, tokenSecret);
    12.      }




                                                                                           10
Linked Data & Semantic Web Technology
Test Code for Authentication
    1.     import     twitter4j.IDs;
    2.     import     twitter4j.Paging;
    3.     import     twitter4j.Twitter;
    4.     import     twitter4j.TwitterException;
    5.     import     twitter4j.TwitterFactory;
    6.     import     twitter4j.User;
    7.     import     twitter4j.auth.AccessToken;

    8.  public class TwitterFriends {
    9.  public static void main(String args[]) {
    10.      Twitter twitter = TwitterFactory.getSingleton();
    11.      AccessToken accessToken = TwitterAccessToken.loadAccessToken();
    12.      twitter.setOAuthConsumer(TwitterAccessToken.consumerKey,
    13.                TwitterAccessToken.consumerSecret);
    14.      twitter.setOAuthAccessToken(accessToken);
    15.      IDs ids = null;
    16.      try {
    17.           ids = twitter.getFollowersIDs(-1);
    18.      } catch (TwitterException e) {
    19.           // TODO Auto-generated catch block
    20.           e.printStackTrace();
    21.      }
    22.      long[] idArray = ids.getIDs();
    23.      for (int i = 0; i < idArray.length; i++) {
    24.           User u = null;
    25.           try {
    26.                u = twitter.showUser(idArray[i]);
    27.           } catch (TwitterException e) {
    28.                // TODO Auto-generated catch block
    29.                e.printStackTrace();
    30.           }
    31.           System.out.println("Name: " + u.getName());
    32.      }
    33. }
    34. }




                                                                               11
Linked Data & Semantic Web Technology
References
    •      http://en.wikipedia.org/wiki/Oauth
    •      http://twitter4j.org/en/index.html
    •      http://www.semantics.kr/?p=185




                                                12
Linked Data & Semantic Web Technology

More Related Content

Similar to Development of Twitter Application #3 - OAuth

Building TweetEngine
Building TweetEngineBuilding TweetEngine
Building TweetEngineikailan
 
Development of Twitter Application #4 - Timeline and Tweet
Development of Twitter Application #4 - Timeline and TweetDevelopment of Twitter Application #4 - Timeline and Tweet
Development of Twitter Application #4 - Timeline and Tweet
Myungjin Lee
 
SgCodeJam24 Workshop Extract
SgCodeJam24 Workshop ExtractSgCodeJam24 Workshop Extract
SgCodeJam24 Workshop Extract
remko caprio
 
Microservices Manchester: Security, Microservces and Vault by Nicki Watt
Microservices Manchester:  Security, Microservces and Vault by Nicki WattMicroservices Manchester:  Security, Microservces and Vault by Nicki Watt
Microservices Manchester: Security, Microservces and Vault by Nicki Watt
OpenCredo
 
Centralise legacy auth at the ingress gateway, SREday
Centralise legacy auth at the ingress gateway, SREdayCentralise legacy auth at the ingress gateway, SREday
Centralise legacy auth at the ingress gateway, SREday
Andrew Kirkpatrick
 
Centralise legacy auth at the ingress gateway
Centralise legacy auth at the ingress gatewayCentralise legacy auth at the ingress gateway
Centralise legacy auth at the ingress gateway
Andrew Kirkpatrick
 
OAuth and OEmbed
OAuth and OEmbedOAuth and OEmbed
OAuth and OEmbed
leahculver
 
Secure Webservices
Secure WebservicesSecure Webservices
Secure Webservices
Matthias Käppler
 
Mining Social Web APIs with IPython Notebook (Data Day Texas 2015)
Mining Social Web APIs with IPython Notebook (Data Day Texas 2015)Mining Social Web APIs with IPython Notebook (Data Day Texas 2015)
Mining Social Web APIs with IPython Notebook (Data Day Texas 2015)
Matthew Russell
 
Mining Social Web APIs with IPython Notebook (PyCon 2014)
Mining Social Web APIs with IPython Notebook (PyCon 2014)Mining Social Web APIs with IPython Notebook (PyCon 2014)
Mining Social Web APIs with IPython Notebook (PyCon 2014)
Matthew Russell
 
Develop IoT project with AirVantage M2M Cloud
Develop IoT project with AirVantage M2M CloudDevelop IoT project with AirVantage M2M Cloud
Develop IoT project with AirVantage M2M Cloud
Crystal Lam
 
Social media analysis in R using twitter API
Social media analysis in R using twitter API Social media analysis in R using twitter API
Social media analysis in R using twitter API
Mohd Shadab Alam
 
Linkedin & OAuth
Linkedin & OAuthLinkedin & OAuth
Linkedin & OAuth
Umang Goyal
 
Understanding Windows Access Token Manipulation
Understanding Windows Access Token ManipulationUnderstanding Windows Access Token Manipulation
Understanding Windows Access Token Manipulation
Justin Bui
 
Real World Asp.Net WebApi Applications
Real World Asp.Net WebApi ApplicationsReal World Asp.Net WebApi Applications
Real World Asp.Net WebApi Applications
Effie Arditi
 
Spring Social - Messaging Friends & Influencing People
Spring Social - Messaging Friends & Influencing PeopleSpring Social - Messaging Friends & Influencing People
Spring Social - Messaging Friends & Influencing People
Gordon Dickens
 
How to Get Twitter Data Using QGIS and Python
How to Get Twitter Data Using QGIS and PythonHow to Get Twitter Data Using QGIS and Python
How to Get Twitter Data Using QGIS and Python
NopphawanTamkuan
 
R project(Analyze Twitter with R)
R project(Analyze Twitter with R)R project(Analyze Twitter with R)
R project(Analyze Twitter with R)
Lovely Professional University
 
Mobile Authentication - Onboarding, best practices & anti-patterns
Mobile Authentication - Onboarding, best practices & anti-patternsMobile Authentication - Onboarding, best practices & anti-patterns
Mobile Authentication - Onboarding, best practices & anti-patterns
Pieter Ennes
 
Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)danwrong
 

Similar to Development of Twitter Application #3 - OAuth (20)

Building TweetEngine
Building TweetEngineBuilding TweetEngine
Building TweetEngine
 
Development of Twitter Application #4 - Timeline and Tweet
Development of Twitter Application #4 - Timeline and TweetDevelopment of Twitter Application #4 - Timeline and Tweet
Development of Twitter Application #4 - Timeline and Tweet
 
SgCodeJam24 Workshop Extract
SgCodeJam24 Workshop ExtractSgCodeJam24 Workshop Extract
SgCodeJam24 Workshop Extract
 
Microservices Manchester: Security, Microservces and Vault by Nicki Watt
Microservices Manchester:  Security, Microservces and Vault by Nicki WattMicroservices Manchester:  Security, Microservces and Vault by Nicki Watt
Microservices Manchester: Security, Microservces and Vault by Nicki Watt
 
Centralise legacy auth at the ingress gateway, SREday
Centralise legacy auth at the ingress gateway, SREdayCentralise legacy auth at the ingress gateway, SREday
Centralise legacy auth at the ingress gateway, SREday
 
Centralise legacy auth at the ingress gateway
Centralise legacy auth at the ingress gatewayCentralise legacy auth at the ingress gateway
Centralise legacy auth at the ingress gateway
 
OAuth and OEmbed
OAuth and OEmbedOAuth and OEmbed
OAuth and OEmbed
 
Secure Webservices
Secure WebservicesSecure Webservices
Secure Webservices
 
Mining Social Web APIs with IPython Notebook (Data Day Texas 2015)
Mining Social Web APIs with IPython Notebook (Data Day Texas 2015)Mining Social Web APIs with IPython Notebook (Data Day Texas 2015)
Mining Social Web APIs with IPython Notebook (Data Day Texas 2015)
 
Mining Social Web APIs with IPython Notebook (PyCon 2014)
Mining Social Web APIs with IPython Notebook (PyCon 2014)Mining Social Web APIs with IPython Notebook (PyCon 2014)
Mining Social Web APIs with IPython Notebook (PyCon 2014)
 
Develop IoT project with AirVantage M2M Cloud
Develop IoT project with AirVantage M2M CloudDevelop IoT project with AirVantage M2M Cloud
Develop IoT project with AirVantage M2M Cloud
 
Social media analysis in R using twitter API
Social media analysis in R using twitter API Social media analysis in R using twitter API
Social media analysis in R using twitter API
 
Linkedin & OAuth
Linkedin & OAuthLinkedin & OAuth
Linkedin & OAuth
 
Understanding Windows Access Token Manipulation
Understanding Windows Access Token ManipulationUnderstanding Windows Access Token Manipulation
Understanding Windows Access Token Manipulation
 
Real World Asp.Net WebApi Applications
Real World Asp.Net WebApi ApplicationsReal World Asp.Net WebApi Applications
Real World Asp.Net WebApi Applications
 
Spring Social - Messaging Friends & Influencing People
Spring Social - Messaging Friends & Influencing PeopleSpring Social - Messaging Friends & Influencing People
Spring Social - Messaging Friends & Influencing People
 
How to Get Twitter Data Using QGIS and Python
How to Get Twitter Data Using QGIS and PythonHow to Get Twitter Data Using QGIS and Python
How to Get Twitter Data Using QGIS and Python
 
R project(Analyze Twitter with R)
R project(Analyze Twitter with R)R project(Analyze Twitter with R)
R project(Analyze Twitter with R)
 
Mobile Authentication - Onboarding, best practices & anti-patterns
Mobile Authentication - Onboarding, best practices & anti-patternsMobile Authentication - Onboarding, best practices & anti-patterns
Mobile Authentication - Onboarding, best practices & anti-patterns
 
Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)
 

More from Myungjin Lee

지식그래프 개념과 활용방안 (Knowledge Graph - Introduction and Use Cases)
지식그래프 개념과 활용방안 (Knowledge Graph - Introduction and Use Cases)지식그래프 개념과 활용방안 (Knowledge Graph - Introduction and Use Cases)
지식그래프 개념과 활용방안 (Knowledge Graph - Introduction and Use Cases)
Myungjin Lee
 
JSP 프로그래밍 #05 HTML과 JSP
JSP 프로그래밍 #05 HTML과 JSPJSP 프로그래밍 #05 HTML과 JSP
JSP 프로그래밍 #05 HTML과 JSP
Myungjin Lee
 
JSP 프로그래밍 #04 JSP 의 기본
JSP 프로그래밍 #04 JSP 의 기본JSP 프로그래밍 #04 JSP 의 기본
JSP 프로그래밍 #04 JSP 의 기본
Myungjin Lee
 
JSP 프로그래밍 #03 서블릿
JSP 프로그래밍 #03 서블릿JSP 프로그래밍 #03 서블릿
JSP 프로그래밍 #03 서블릿
Myungjin Lee
 
JSP 프로그래밍 #02 서블릿과 JSP 시작하기
JSP 프로그래밍 #02 서블릿과 JSP 시작하기JSP 프로그래밍 #02 서블릿과 JSP 시작하기
JSP 프로그래밍 #02 서블릿과 JSP 시작하기
Myungjin Lee
 
JSP 프로그래밍 #01 웹 프로그래밍
JSP 프로그래밍 #01 웹 프로그래밍JSP 프로그래밍 #01 웹 프로그래밍
JSP 프로그래밍 #01 웹 프로그래밍
Myungjin Lee
 
관광 지식베이스와 스마트 관광 서비스 (Knowledge base and Smart Tourism)
관광 지식베이스와 스마트 관광 서비스 (Knowledge base and Smart Tourism)관광 지식베이스와 스마트 관광 서비스 (Knowledge base and Smart Tourism)
관광 지식베이스와 스마트 관광 서비스 (Knowledge base and Smart Tourism)
Myungjin Lee
 
오픈 데이터와 인공지능
오픈 데이터와 인공지능오픈 데이터와 인공지능
오픈 데이터와 인공지능
Myungjin Lee
 
법령 온톨로지의 구축 및 검색
법령 온톨로지의 구축 및 검색법령 온톨로지의 구축 및 검색
법령 온톨로지의 구축 및 검색
Myungjin Lee
 
도서관과 Linked Data
도서관과 Linked Data도서관과 Linked Data
도서관과 Linked Data
Myungjin Lee
 
공공데이터, 현재 우리는?
공공데이터, 현재 우리는?공공데이터, 현재 우리는?
공공데이터, 현재 우리는?
Myungjin Lee
 
LODAC 2017 Linked Open Data Workshop
LODAC 2017 Linked Open Data WorkshopLODAC 2017 Linked Open Data Workshop
LODAC 2017 Linked Open Data Workshop
Myungjin Lee
 
Introduction of Deep Learning
Introduction of Deep LearningIntroduction of Deep Learning
Introduction of Deep Learning
Myungjin Lee
 
쉽게 이해하는 LOD
쉽게 이해하는 LOD쉽게 이해하는 LOD
쉽게 이해하는 LOD
Myungjin Lee
 
서울시 열린데이터 광장 문화관광 분야 LOD 서비스
서울시 열린데이터 광장 문화관광 분야 LOD 서비스서울시 열린데이터 광장 문화관광 분야 LOD 서비스
서울시 열린데이터 광장 문화관광 분야 LOD 서비스
Myungjin Lee
 
LOD(Linked Open Data) Recommendations
LOD(Linked Open Data) RecommendationsLOD(Linked Open Data) Recommendations
LOD(Linked Open Data) Recommendations
Myungjin Lee
 
Interlinking for Linked Data
Interlinking for Linked DataInterlinking for Linked Data
Interlinking for Linked Data
Myungjin Lee
 
Linked Open Data Tutorial
Linked Open Data TutorialLinked Open Data Tutorial
Linked Open Data Tutorial
Myungjin Lee
 
Linked Data Usecases
Linked Data UsecasesLinked Data Usecases
Linked Data Usecases
Myungjin Lee
 
공공데이터와 Linked open data
공공데이터와 Linked open data공공데이터와 Linked open data
공공데이터와 Linked open data
Myungjin Lee
 

More from Myungjin Lee (20)

지식그래프 개념과 활용방안 (Knowledge Graph - Introduction and Use Cases)
지식그래프 개념과 활용방안 (Knowledge Graph - Introduction and Use Cases)지식그래프 개념과 활용방안 (Knowledge Graph - Introduction and Use Cases)
지식그래프 개념과 활용방안 (Knowledge Graph - Introduction and Use Cases)
 
JSP 프로그래밍 #05 HTML과 JSP
JSP 프로그래밍 #05 HTML과 JSPJSP 프로그래밍 #05 HTML과 JSP
JSP 프로그래밍 #05 HTML과 JSP
 
JSP 프로그래밍 #04 JSP 의 기본
JSP 프로그래밍 #04 JSP 의 기본JSP 프로그래밍 #04 JSP 의 기본
JSP 프로그래밍 #04 JSP 의 기본
 
JSP 프로그래밍 #03 서블릿
JSP 프로그래밍 #03 서블릿JSP 프로그래밍 #03 서블릿
JSP 프로그래밍 #03 서블릿
 
JSP 프로그래밍 #02 서블릿과 JSP 시작하기
JSP 프로그래밍 #02 서블릿과 JSP 시작하기JSP 프로그래밍 #02 서블릿과 JSP 시작하기
JSP 프로그래밍 #02 서블릿과 JSP 시작하기
 
JSP 프로그래밍 #01 웹 프로그래밍
JSP 프로그래밍 #01 웹 프로그래밍JSP 프로그래밍 #01 웹 프로그래밍
JSP 프로그래밍 #01 웹 프로그래밍
 
관광 지식베이스와 스마트 관광 서비스 (Knowledge base and Smart Tourism)
관광 지식베이스와 스마트 관광 서비스 (Knowledge base and Smart Tourism)관광 지식베이스와 스마트 관광 서비스 (Knowledge base and Smart Tourism)
관광 지식베이스와 스마트 관광 서비스 (Knowledge base and Smart Tourism)
 
오픈 데이터와 인공지능
오픈 데이터와 인공지능오픈 데이터와 인공지능
오픈 데이터와 인공지능
 
법령 온톨로지의 구축 및 검색
법령 온톨로지의 구축 및 검색법령 온톨로지의 구축 및 검색
법령 온톨로지의 구축 및 검색
 
도서관과 Linked Data
도서관과 Linked Data도서관과 Linked Data
도서관과 Linked Data
 
공공데이터, 현재 우리는?
공공데이터, 현재 우리는?공공데이터, 현재 우리는?
공공데이터, 현재 우리는?
 
LODAC 2017 Linked Open Data Workshop
LODAC 2017 Linked Open Data WorkshopLODAC 2017 Linked Open Data Workshop
LODAC 2017 Linked Open Data Workshop
 
Introduction of Deep Learning
Introduction of Deep LearningIntroduction of Deep Learning
Introduction of Deep Learning
 
쉽게 이해하는 LOD
쉽게 이해하는 LOD쉽게 이해하는 LOD
쉽게 이해하는 LOD
 
서울시 열린데이터 광장 문화관광 분야 LOD 서비스
서울시 열린데이터 광장 문화관광 분야 LOD 서비스서울시 열린데이터 광장 문화관광 분야 LOD 서비스
서울시 열린데이터 광장 문화관광 분야 LOD 서비스
 
LOD(Linked Open Data) Recommendations
LOD(Linked Open Data) RecommendationsLOD(Linked Open Data) Recommendations
LOD(Linked Open Data) Recommendations
 
Interlinking for Linked Data
Interlinking for Linked DataInterlinking for Linked Data
Interlinking for Linked Data
 
Linked Open Data Tutorial
Linked Open Data TutorialLinked Open Data Tutorial
Linked Open Data Tutorial
 
Linked Data Usecases
Linked Data UsecasesLinked Data Usecases
Linked Data Usecases
 
공공데이터와 Linked open data
공공데이터와 Linked open data공공데이터와 Linked open data
공공데이터와 Linked open data
 

Recently uploaded

Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 

Recently uploaded (20)

Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 

Development of Twitter Application #3 - OAuth

  • 1. Linked Data & Semantic Web Technology Development of Twitter Applications Part 3. OAuth Dr. Myungjin Lee
  • 2. Twitter4J • What is Twitter4J? – an unofficial Java library for the Twitter API – easily to integrate your Java application with the Twitter service – http://twitter4j.org/en/index.html • Features – 100% Pure Java - works on any Java Platform version 5 or later – Android platform and Google App Engine ready – Zero dependency : No additional jars required – Built-in OAuth support – Out-of-the-box gzip support – 100% Twitter API 1.1 compatible • API Support matrix – http://twitter4j.org/en/api-support.html 2 Linked Data & Semantic Web Technology
  • 3. OAuth • What is OAuth? – an open standard for authorization – a method for clients to access server resources on behalf of a resource owner – a process for end-users to authorize third-party access to their server resources without sharing their credentials • Twitter’s OAuth – OAuth v1.0a to provide authorized access to Twitter API – using HMAC-SHA1 signature 3 Linked Data & Semantic Web Technology
  • 4. OAuth Process for Desktop Application 4 Linked Data & Semantic Web Technology
  • 5. Registering Your Application • https://dev.twitter.com/apps/new your application name your application description your application’s publicly accessible home page webpage URL where twitter returns after successfully authenticating Linked Data & Semantic Web Technology
  • 6. Registering Your Application Consumer Key and Secret to get user’s Access Token 6 Linked Data & Semantic Web Technology
  • 7. Application type • Read only – Read Tweets from your timeline. – See who you follow. • Read and Write – Read Tweets from your timeline. – See who you follow, and follow new people. – Update your profile. – Post Tweets for you. • Read, Write and Access direct messages – Read Tweets from your timeline. – See who you follow, and follow new people. – Update your profile. – Post Tweets for you. – Access your direct messages. 7 Linked Data & Semantic Web Technology
  • 8. Primary Classes and Interfaces of Twitter4J • TwitterFactory Class – A factory class for Twitter • Twitter Interface – basic interface to use all of APIs • AccessToken Class – Representing authorized Access Token which is passed to the service provider in order to access protected resources 8 Linked Data & Semantic Web Technology
  • 9. Getting Access Token 1. // The factory instance is re-useable and thread safe. 2. Twitter twitter = TwitterFactory.getSingleton(); 3. twitter.setOAuthConsumer("[consumer key]", "[consumer secret]"); 4. RequestToken requestToken = null; 5. try { 6. requestToken = twitter.getOAuthRequestToken(); 7. } catch (TwitterException e) { 8. // TODO Auto-generated catch block 9. e.printStackTrace(); 10. } 11. AccessToken accessToken = null; 12. BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 13. while (null == accessToken) { 14. System.out.println("Open the following URL and grant access to your account:"); 15. System.out.println(requestToken.getAuthorizationURL()); 16. System.out.print("Enter the PIN(if aviailable) or just hit enter.[PIN]:"); 17. String pin = new String(); 18. try { 19. pin = br.readLine(); 20. } catch (IOException e) { 21. // TODO Auto-generated catch block 22. e.printStackTrace(); 23. } 24. try { 25. if (pin.length() > 0) { 26. accessToken = twitter.getOAuthAccessToken(requestToken, pin); 27. } else { 28. accessToken = twitter.getOAuthAccessToken(); 29. } 30. } catch (TwitterException te) { 31. if (401 == te.getStatusCode()) { 32. System.out.println("Unable to get the access token."); 33. } else { 34. te.printStackTrace(); 35. } 36. } 37. } 38. // persist to the accessToken for future reference. 39. try { 40. storeAccessToken(twitter.verifyCredentials().getId(), accessToken); 41. } catch (TwitterException e) { 42. // TODO Auto-generated catch block 43. e.printStackTrace(); 44. } 9 Linked Data & Semantic Web Technology
  • 10. Getting Access Token 1. private static void storeAccessToken(long useId, AccessToken accessToken) { 2. // store accessToken.getToken() and accessToken.getTokenSecret() 3. System.out.println("User ID: " + useId); 4. System.out.println("Access Token: " + accessToken.getToken()); 5. System.out.println("Access Token Secret: " 6. + accessToken.getTokenSecret()); 7. } 8. public static AccessToken loadAccessToken() { 9. String token = "[access token]"; 10. String tokenSecret = "[access token secret]"; 11. return new AccessToken(token, tokenSecret); 12. } 10 Linked Data & Semantic Web Technology
  • 11. Test Code for Authentication 1. import twitter4j.IDs; 2. import twitter4j.Paging; 3. import twitter4j.Twitter; 4. import twitter4j.TwitterException; 5. import twitter4j.TwitterFactory; 6. import twitter4j.User; 7. import twitter4j.auth.AccessToken; 8. public class TwitterFriends { 9. public static void main(String args[]) { 10. Twitter twitter = TwitterFactory.getSingleton(); 11. AccessToken accessToken = TwitterAccessToken.loadAccessToken(); 12. twitter.setOAuthConsumer(TwitterAccessToken.consumerKey, 13. TwitterAccessToken.consumerSecret); 14. twitter.setOAuthAccessToken(accessToken); 15. IDs ids = null; 16. try { 17. ids = twitter.getFollowersIDs(-1); 18. } catch (TwitterException e) { 19. // TODO Auto-generated catch block 20. e.printStackTrace(); 21. } 22. long[] idArray = ids.getIDs(); 23. for (int i = 0; i < idArray.length; i++) { 24. User u = null; 25. try { 26. u = twitter.showUser(idArray[i]); 27. } catch (TwitterException e) { 28. // TODO Auto-generated catch block 29. e.printStackTrace(); 30. } 31. System.out.println("Name: " + u.getName()); 32. } 33. } 34. } 11 Linked Data & Semantic Web Technology
  • 12. References • http://en.wikipedia.org/wiki/Oauth • http://twitter4j.org/en/index.html • http://www.semantics.kr/?p=185 12 Linked Data & Semantic Web Technology