Twitter API using Twitter4j

oauth
twitter4j
java

#1

Hi, I am new to this, I want to develop an application using java (twitter4j) which will stream direct messages (DM) posted to my twitter account and will post direct message to my followers.
Everyone says to create an app in twitter first to get the consumer key and secret. But app asks for website and callback URL. I don’t have one.

Please suggest how do I connect to my twitter account to read and post messages programatically.

Thanks
Kiran


#2

It’s fine to use a placeholder callback url (eg: example.com) if you don’t have one & don’t intend on using one.

Once you create your app, and your Access Token & Secret you’ll be able to run these examples: https://github.com/yusuke/twitter4j/blob/master/twitter4j-examples/src/main/java/twitter4j/examples/stream/PrintUserStream.java#L111 to run the stream and listen to new DMs & https://github.com/yusuke/twitter4j/tree/master/twitter4j-examples/src/main/java/twitter4j/examples/directmessage to do other stuff.


#3

Thank you…
I have one further query, which account (twitter handle) does it use?


#4

Depends on the Access Token: If you use the Consumer Key & Secret and the Access Token & Secret under “Keys & access tokens” in https://apps.twitter.com it’ll be the “Owner” (same account as the one that created the application) but you can always authorize a different account eg: https://github.com/yusuke/twitter4j/blob/master/twitter4j-examples/src/main/java/twitter4j/examples/oauth/GetAccessToken.java (same Consumer Keys, but different Access tokens) and use that instead.