Thank you. But I tried with lookupUsers but it doesnât work. Can you help me again. Where should i write lookupUsers(id) ?
I tried also this code :
try {
TwitterFactory tf=new TwitterFactory(cb.build());
twitter4j.Twitter tw=tf.getInstance();
ResponseList<User> users = tw.lookupUsers(args[0].split(","));
for (User user : users) {
if (null != user.getStatus()) {
System.out.println("@" + user.getScreenName() + " - " + user.getStatus().getText());
} else {
// the user is protected
System.out.println("@" + user.getScreenName());
}
}
System.out.println("Successfully looked up users [" + args[0] + "].");
System.exit(0);
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to lookup users: " + te.getMessage());
System.exit(-1);
}
Is this code give me the name of folloawers? but when i wrote it, it give me exception and i didnât know how i correct it.
this exception appears :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at projet1.Mon_Application.main(Mon_Application.java:104)
Can you help me?
Other question please:
My application can display the timeline, write a tweet and write direct message but these functionalities work only on my account (from my application and my twitter account) now i want to access to other accounts of users. They should write their emails and their passwords in my application and my application should display for the user his timeline, he can also write a tweet in his account of twitterâŚ
What should i do to connect the twitter account of any user with my application. My appliacation consist in doing a twitter USSD application.
Can you help me please?
Should i write this or something else?
Initially, you donât have a permission to access the userâs account and need to acquire access token by redirecting the user to an authorization URL as follows:
public static void main(String args[]) throws Exception{
// The factory instance is re-useable and thread safe.
Twitter twitter = TwitterFactory.getSingleton();
twitter.setOAuthConsumer("[consumer key]", "[consumer secret]");
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() + "].");
System.exit(0);
}
private static void storeAccessToken(int useId, AccessToken accessToken){
//store accessToken.getToken()
//store accessToken.getTokenSecret()
}
After you acquired the AccessToken for the user, the RequestToken is not required anymore. You can persist the AccessToken to any kind of persistent store such as RDBMS, or File system by serializing the object, or by geting the token and the secret from AccessToken#getToken() and AccessToken#getTokenSecret().
public static void main(String args[]) throws Exception{
// The factory instance is re-useable and thread safe.
TwitterFactory factory = new TwitterFactory();
AccessToken accessToken = loadAccessToken(Integer.parseInt(args[0]));
Twitter twitter = factory.getInstance();
twitter.setOAuthConsumerKey("[consumer key]", "[consumer secret]");
twitter.setOAuthAccessToken(accessToken);
Status status = twitter.updateStatus(args[1]);
System.out.println("Successfully updated the status to [" + status.getText() + "].");
System.exit(0);
}
private static AccessToken loadAccessToken(int useId){
String token = // load from a persistent store
String tokenSecret = // load from a persistent store
return new AccessToken(token, tokenSecret);
}
Because i didânt understand them.
Sorry but i need help and thank you very much .