Twitter APIs and authentication


#1

Hi,

I have two questions. First of all, i’m building an app which should keep on searching tweets based on a specific keyword , filter, do some processing and persists in database. The app will be displaying some statistical analysis details based on the data retreived and processed. The webpage will be refreshing in timely manner to show new data received and processed. To address this kind of scenario, which API should i consider as the best option?

Also, i’m using twitter4j as client. The following code throws:

401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, acc
ess token/secret, and the system clock is in sync.
The screen name / password combination seems to be invalid.

What can be the problem? I have verified the keys and they seems to be fine.

try {
	Twitter twitter = TwitterFactory.getSingleton();
	twitter.setOAuthConsumer("xxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxx");

	RequestToken twitterRequestToken = twitter.getOAuthRequestToken();
	String token = twitterRequestToken.getToken();
	String tokenSecret = twitterRequestToken.getTokenSecret();

	AccessToken accessToken =  twitter.getOAuthAccessToken(token, tokenSecret);
	twitter.setOAuthAccessToken(accessToken);

        Query query = new Query("source:twitter4j yusukey");
        QueryResult result = twitter.search(query);
        for (Status status : result.getTweets()) {
    	   log.info("@" + status.getUser().getScreenName() + ":" + status.getText());
        }
	} catch (Exception e) {
		e.printStackTrace();
	}
 
   Thanks.

#2

I am facing the same problem :frowning:


#3

I have also the same problem. But what is strange is that the code running on my server seems to work : colafight.com is updated as it should.
But when I try to run excactly the same code in my dev environment I get an 401 error. It was working yesterday.
I use VB.NET. Here is how I connect,btw.

Dim encode As Encoding = Encoding.GetEncoding(“utf-8”)

    Dim url As String = "https://stream.twitter.com/1.1/statuses/filter.json?track=cocacola,pepsi,coca-cola,rccola"
        Dim request As WebRequest = WebRequest.Create(url)
    request.Credentials = New NetworkCredential("xxxxx", "xxxxxx")
        Dim WebResponse = request.GetResponse()

        Dim responseStream = New StreamReader(WebResponse.GetResponseStream(), encode)




        'JSON Parse

        While Not responseStream.EndOfStream
        Console.WriteLine(responseStream.ReadLine())

            Dim json As String = responseStream.ReadLine()
            If json.Length <> 0 Then
                ParseJson(json)
            End If
        End While

#4