I want to get user tweets with http request to twitter api.
@Override
public void run() {
try {
URL url = new URL("https://api.twitter.com/1/statuses/home_timeline.json");
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setDoOutput(true);
httpCon.setRequestMethod("GET"); //same error with POST
OutputStreamWriter out = new OutputStreamWriter(httpCon.getOutputStream());
System.out.println(httpCon.getResponseCode());
System.out.println(httpCon.getResponseMessage());
out.close();
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}
}
But I am getting error 404. If I change version from 1.1 to 1 the it gives me error 410.
I have already created my account in developer site and have generated all of my tokens and keys.
can Anybody tell me how to authenticate to twitter?
NOTE:I am able to sign up with fabric sdk.
Regards.
3
Answers
Rather using plane old URL class i would recomend to use any standard API to communicate with twitter like http://twitter4j.org/
Code sample to check timeline
To check other users time line :
This is full code Twitter.
https://github.com/shivagss/AndroidTwitterClient
Hope. It will help you !!!
There are different libraries to get Twitter Tweets like:
1.Twitter4j Library
If you are using Android studio then it has Android Studio Plugin which will configure easily Twitter.
Hope this help.