Jump to content



Photo

Twitter API oauth help

java twitter api oauth

  • Please log in to reply
4 replies to this topic

#1 thatguyandrew1992

thatguyandrew1992

    Neowinian Senior

  • Tech Issues Solved: 4
  • Joined: 22-January 09

Posted 21 November 2012 - 09:34

So I'm making a twitter program and this is the first time ive used the twitter api, or any api for that matter.
I created my app with dev.twitter.com.

Everytime I run the program i have to go enter the given url from the program into my browser, authorize the program to work with my twitter account, then enter a PIN that I am given.

Is there anyway I can skip doing this EVERYTIME? I authorized it once, isn't that enough?

Also, can someone explain all the different keys, secrets and tokens? I'm very confused.

Im using Twitter4j
// The factory instance is re-useable and thread safe.
   	 Twitter twitter = new TwitterFactory().getInstance();
   	 twitter.setOAuthConsumer("secretness!!", "secretness!!");
   	 RequestToken requestToken = twitter.getOAuthRequestToken();
   	 AccessToken accessToken = null;
   	 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   	 while (null == accessToken) {
   	   System.out.println("Open the following URL and grant access to your account:");
   	   System.out.println(requestToken.getAuthorizationURL());
   	   System.out.print("Enter the PIN(if aviailable) or just hit enter.[PIN]:");
   	   String pin = br.readLine();
   	   try{
   		  if(pin.length() > 0){
   			accessToken = twitter.getOAuthAccessToken(requestToken, pin);
   		  }else{
   			accessToken = twitter.getOAuthAccessToken();
   		  }
   	   } catch (TwitterException te) {
   		 if(401 == te.getStatusCode()){
   		   System.out.println("Unable to get the access token.");
   		 }else{
   		   te.printStackTrace();
   		 }
   	   }
   	 }
   	 //persist to the accessToken for future reference.
   	 storeAccessToken(twitter.verifyCredentials().getId() , accessToken);
   	 //Status status = twitter.updateStatus(args[0]);
   	 //System.out.println("Successfully updated the status to [" + status.getText() + "].");




#2 OP thatguyandrew1992

thatguyandrew1992

    Neowinian Senior

  • Tech Issues Solved: 4
  • Joined: 22-January 09

Posted 22 November 2012 - 02:56

Anyone pleaseeee! What do I need to do, to save this authorization?

#3 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 14
  • Joined: 26-October 05

Posted 22 November 2012 - 19:49

I don't know, but you might want to ask at https://dev.twitter.com/discussions .

#4 Paramore™

Paramore™

    Neowinian

  • Joined: 01-December 11
  • Location: Los Angeles
  • OS: Windows 7 Ultimate

Posted 22 November 2012 - 19:50

Use their "remember" feature.

#5 OP thatguyandrew1992

thatguyandrew1992

    Neowinian Senior

  • Tech Issues Solved: 4
  • Joined: 22-January 09

Posted 23 November 2012 - 23:57

Use their "remember" feature.

Do you know where I can find information on that feature?