• 0

Twitter API oauth help


Question

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() + "].");

[/CODE]

Link to comment
https://www.neowin.net/forum/topic/1121180-twitter-api-oauth-help/
Share on other sites

4 answers to this question

Recommended Posts

This topic is now closed to further replies.
  • Posts

    • Playground drops 30 minutes of Fable gameplay, shows off life sim and morality system by Pulasthi Ariyasinghe Playground Games gave fantasy RPG fans a new look at its Fable reboot last Sunday at the Xbox Games Showcase. While that was a short cinematic trailer revealing the main villain of the storyline, played by Hayley Atwell, today, the development team released an entire gameplay demo to show off the game in action. There is some combat and action near the end of it, but most of the demo is focused on the game's NPC simulation, relationships, choices players can make, and the complex reputation system. The studio is touting over 1,000 hand-crafted NPCs who have jobs, homes, routines they follow in their villages and outskirts, and a memory of what is going on in the world and what actions the player has done. All of these are voiced by real people too. The demo begins with a short interaction with a butcher who wants to kill a talking pig named Colin. The protagonist chooses to save Colin by paying the butcher a bunch of gold for his troubles, giving the hero a rise in reputation for being shrewd, merciful, and virtuous. There were also options to simply let Colin get killed or even fight the butcher for the pig instead of paying him. How NPCs judge the player depends on how they interact with the world. https://www.youtube.com/watch?v=doV0yq4kAP0 Later, the demo shows off how purchasing and managing businesses work, where players can hire employees, change their wages, tweak the price of the shop items, and reap profits if they do well. Different NPCs react differently to each type of reputation the player is touting. One shop owner jacks up prices by 80% just because the player is rich and owns businesses. The demo even shows the player deciding to attack random villagers and causing a ruckus in the streets, turning the hero into a criminal. This is where the magic combat systems are shown off, where the player can teleport, turn enemies into chickens, sword-fight, and more. "This is how you’ll build an extraordinary life in Fable. It’s all about shades of grey – it’s not us or the game telling you what is good and what is bad," says Dan Greer, Lead Game Designer. "With the Living Population, it’s the NPCs themselves judging your actions." Fable is releasing across PC and Xbox Series X|S on February 23, 2027. Premium Edition owners will be able to play starting on February 18 instead. Xbox Game Pass subscribers will also be able to jump in at launch for no extra cost.
    • Still 93% off: Microsoft Visual Studio Professional 2026 lifetime digital license by Steven Parker Today's highlighted deal comes via our Apps + Software section of the Neowin Deals store, where for a limited time you can still save 93% on Microsoft Visual Studio Professional 2026. Code Faster, Work Smarter with Visual Studio 2026 Visual Studio Professional 2026 is a fully featured development environment that developers around the world know & love — now enhanced with deeper AI integration, improved performance & more powerful collaboration tools. Built as a 64-bit IDE, it makes it easier than ever to work with very large solutions & complex workloads. Boost your productivity, write high-quality code & re-imagine team collaboration with an advanced suite of tools & built-in integrations designed to tackle the most demanding development workflows & deliver modern, cloud-connected applications. Build across languages and platforms Craft cross-platform mobile & desktop apps with .NET MAUI Build responsive Web UIs in C# with Blazor Build, debug, & test .NET & C++ apps targeting Windows, Linux & containers Use hot reload capabilities across .NET & C++ apps to apply code changes instantly Edit running ASP.NET/ASP.NET Core pages in the web designer view Integrate seamlessly with Azure, GitHub & other DevOps workflows Type less, code more with Intellicode and AI Understand your code context: variable names, functions, libraries & the type of code you’re writing Complete a line or block of code based on patterns learned from your codebase Get a ranked list of next best suggestions, helping you code more rapidly & accurately Use built-in AI-assisted refactoring & code suggestions to reduce bugs & boilerplate Gain deep insights into your code with codelens Reveal crucial information such as recent changes, authors, tests & commit history directly in the editor See test status & references without leaving your code Make informed decisions with a comprehensive overview of your codebase and activity Collaborate seamlessly with live share Run real-time collaboration sessions with teammates — no need for them to clone repos or install all dependencies Speed up your team’s edit & debugging cycles with personalized sessions, access controls & custom editor settings Keep everyone aligned so your team’s code stays consistent & maintainable Good to know Length of access: Lifetime License type: Professional, single-user license Redemption deadline: Redeem your code within 30 days of purchase Access options: Desktop installation on supported Windows operating systems Max number of device(s): 1 Version: Visual Studio Professional 2026 Languages supported: English, Chinese (Simplified), Chinese (Traditional), Czech, French, German, Italian, Japanese, Korean, Polish, Portuguese (Brazil), Russian, Spanish, and Turkish. Updates included: Minor updates and security fixes for the 2026 Professional release channel (according to Microsoft’s lifecycle policy) Activation method: Online activation with Microsoft account required Microsoft Visual Studio Professional 2026 normally costs $499.99, but this deal can be yours for just $34.97, that's a saving of $465. For full terms, specifications, and license info please click the link below. Get Visual Studio 2026 now for just $34.97 (was $499.99) Time limited deal Although priced in U.S. dollars, this deal is available for digital purchase worldwide. Support queries If you have queries or need support for any of the Neowin Deals, please use the contact form here. Neowin Deals are managed and sold by StackCommerce who represent Neowin on an affiliate basis. Why we post these deals We post these because we earn commission on each sale so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. So for those that keep moaning and complaining, be thankful we're still online for you to even do that. Other ways to support Neowin Whitelist Neowin by not blocking our ads Create a free member account to see fewer ads Make a donation to support our day to day running costs Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: Neowin benefits from revenue of each sale made through our branded deals site powered by StackCommerce.
    • My current phone, on left, is starting to go to sleep, and not turning on, even though I press the power button 100 times. Like CPR.   I tried factory resetting it, and nothing changed. So it's the hardware failing. I currently am using Twigby as my service provider. Cheapest I can get around here. But all their phones are carp.. https://www.twigby.com/shop/twigby-phones A friend warned me about the Moto G, as his neice has one, and isn't that good at $130. Also the Samsung A15 is laughable at best. Everything else is expensive af. I want android, (hate iOS) any version, that works with Twigby, under $100, please. Refurbished/Used is OK with me, as long as it isn't beat up.   If you know the IMEI number, you can see if it works with Twigby: https://www.twigby.com/page/byod
    • i not arguing that it isnt ######, only that it does support themes lol.
  • Recent Achievements

    • Week One Done
      StaticMatrix earned a badge
      Week One Done
    • Rookie
      lamborghiniv10 went up a rank
      Rookie
    • One Month Later
      pinnclepd earned a badge
      One Month Later
    • First Post
      X-No-file earned a badge
      First Post
    • One Month Later
      johnjacobb40 earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      516
    2. 2
      PsYcHoKiLLa
      210
    3. 3
      +Edouard
      147
    4. 4
      Steven P.
      91
    5. 5
      ATLien_0
      82
  • Tell a friend

    Love Neowin? Tell a friend!