I want to access twitter data for my algorithm so what will the parameters for callbcak URL and others?


#1

I am getting twitter Exception error so i dont know how to fetch this data


#2

What API are you using? What exactly is the error that you’re seeing, and what kind of code are you writing?


#3
Twitter twitter = new TwitterFactory().getInstance();
 
 twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_KEY_SECRET);
 System.out.println("printed");
 RequestToken requestToken = twitter.getOAuthRequestToken();
 
 System.out.println("Authorization URL: \n"  + requestToken.getAuthorizationURL());

 AccessToken accessToken = null;

Here i am getting exception

twitter.getOAuthRequestToken();


#4

Looks like Twitter4J…
So what’s the exception error message?

I assume you’ve filled in valid consumer key and secret (please don’t share them here, just checking).


#5

yes…
This is exception==========================

Exception in thread “main” api.twitter.comRelevant discussions can be on the Internet at:
http://www.google.co.jp/search?q=bfb606ed or
http://www.google.co.jp/search?q=72d7e395
TwitterException{exceptionCode=[bfb606ed-72d7e395 bfb606ed-72d7e36b], statusCode=-1, retryAfter=-1, rateLimitStatus=null, featureSpecificRateLimitStatus=null, version=2.2.4}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:200)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65)
at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:102)
at twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:121)
at twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:104)
at twitter4j.TwitterBaseImpl.getOAuthRequestToken(TwitterBaseImpl.java:276)
at twitter4j.TwitterBaseImpl.getOAuthRequestToken(TwitterBaseImpl.java:269)
at com.namex.tweet.NamexTweet.start(NamexTweet.java:23)
at com.namex.tweet.NamexTweet.main(NamexTweet.java:56)
Caused by: java.net.UnknownHostException: api.twitter.com
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:378)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:473)
at sun.net.www.http.HttpClient.(HttpClient.java:203)
at sun.net.www.http.HttpClient.New(HttpClient.java:290)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:995)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:931)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:849)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1090)
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:158)
… 8 more


#6

This code works perfectly for me.

import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.auth.AccessToken;
import twitter4j.auth.RequestToken;

public final class sample {

public static void main(String[] args) {
        try {
                Twitter twitter = new TwitterFactory().getInstance();

                twitter.setOAuthConsumer("MY_APP_KEY", "MY_APP_SECRET");
                System.out.println("printed");

                RequestToken requestToken = twitter.getOAuthRequestToken();

                System.out.println("Authorization URL: \n"  + requestToken.getAuthorizationURL());

                AccessToken accessToken = null;
        } catch (TwitterException te) {
                System.out.println(te.getErrorMessage());
        }

}
}

#7

Still it is trowing Exception in my eclipse…
Is their any issue with application?


#8

Really difficult to say what is happening here. I used Twitter4J 4.0.4 to build and run my simple test class (at the command line) and put my key and secret into the code as strings. I’m running using Java 1.8.0.

Just noticed that it looks like you have an UnknownHostException in there - are you able to resolve api.twitter.com from your machine?