Displaying A Twitter User's Timeline - android

I have successfully completed this: http://www.sitepoint.com/loading-twitter-data-into-android-with-lists/ tutorial and have gotten my app to display tweets based on a search criteria.
What I want my app to do is display the timeline of a specific user.
From that tutorial I have replaced my get line with this:
HttpGet("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=android");
I am getting no results in my listview.. I shouldn't need to authenticate user name and password because all I want to do is display the timeline, not manipulate it.

If you are using Twitter4j this is pretty easy :
public final class GetTimelines {
/**
* Usage: java twitter4j.examples.GetTimelines ID Password
* #param args String[]
*/
public static void main(String[] args) {
Twitter unauthenticatedTwitter = new TwitterFactory()
.getInstance();
System.out.println("Showing public timeline.");
try {
List<Status> statuses = unauthenticatedTwitter
.getPublicTimeline();
for (Status status : statuses) {
System.out.println(status.getUser().getName() + ":"
+ status.getText());
}
if (args.length < 2) {
System.out
.println("You need to specify TwitterID/Password combination to show UserTimelines.");
System.out
.println("Usage: java twitter4j.examples.GetTimelines ID Password");
System.exit(0);
}
// Other methods require authentication
Twitter twitter = new TwitterFactory().getInstance(args[0],
args[1]);
statuses = twitter.getFriendsTimeline();
System.out.println("------------------------------");
System.out.println("Showing " + args[0]
+ "'s friends timeline.");
for (Status status : statuses) {
System.out.println(status.getUser().getName() + ":"
+ status.getText());
}
statuses = twitter.getUserTimeline();
System.out.println("------------------------------");
System.out.println("Showing " + args[0] + "'s timeline.");
for (Status status : statuses) {
System.out.println(status.getUser().getName() + ":"
+ status.getText());
}
Status status = twitter.showStatus(81642112l);
System.out.println("------------------------------");
System.out.println("Showing " + status.getUser().getName()
+ "'s status updated at " + status.getCreatedAt());
System.out.println(status.getText());
System.exit(0);
} catch (TwitterException te) {
System.out.println("Failed to get timeline: "
+ te.getMessage());
System.exit(-1);
}
}
}
Sample taken from here

you can get the answer of ur question at https://github.com/robhinds/AndroidTwitterDemo
or
http://automateddeveloper.blogspot.com/2011/06/android-twitter-oauth-authentication.html
use twitter4j jar for same
hope will help u ...

If you just want to fetch user timeline than the best way is -
twitter4j jar file - http://twitter4j.org/archive/twitter4j-3.0.3.zip
To register your app go to dev.twitter.com
We can fetch the use timeline by using twitter oauth and for this process we don't need to provide any user credentials
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
builder.setOAuthAccessToken(TWITTER_ACCESS_KEY);
builder.setOAuthAccessTokenSecret(TWITTER_ACCESS_SECRET);
Configuration configuration = builder.build();
TwitterFactory factory = new TwitterFactory(configuration);
Twitter twitter = factory.getInstance();
Paging page = new Paging();
page.setCount(100);
List<Status> statuses = new ArrayList<Status>();
statuses = twitter.getUserTimeline("write username here", page);
for (Status status : statuses) {
System.out.println("title is : " + status.getText());
}

Twitter has introduced Fabric SDK for needs like yours. Here is a site: Twitter Fabric. When you install SDK you will have new icon in your Android studio for Fabric Sdk. You have to install Twitter kit and use embed tweets. For user timeline you have to use UserTimeline. Also , you have some project in github that can help you understand how Twitter kit works:
Github repo

Related

Android - how to post a Tweet to Twitter directly (without an implicit intent or other application)?

Good afternoon everybody. I'm following this tutorial:
http://www.androidwarriors.com/2015/11/twitter-login-android-studio-example.html
which has this associated GitHub project:
https://github.com/androidwarriors/TwitterLoginUsingFabric
Everything seems to be working, when I get to the lines:
String msg = "#" + session.getUserName() + " logged in! (#" + session.getUserId() + ")";
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
TweetComposer.Builder builder = new TweetComposer.Builder(MainActivity.this).text("test tweet 789");
builder.show();
getUserData();
I am able to see the Toast confirming successful login and then apparently an implicit intent is started, the phone asks which browser I would prefer to use, then opens that browser with "test tweet 789" already entered and a button to send the tweet.
The concern is, I would like to directly send the tweet from my app, rather than bringing up a browser as a separate app to do so. Is there a way to do this? Seems like an easy question and it's probably only another line of code or two but I could not find a directly applicable example, please advise. Sorry if I'm missing something easy here.
For the record here is my entire onCreate method, mostly directly from the tutorial linked above.
///////////////////////////////////////////////////////////////////////////////////////////////
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
Fabric.with(this, new Twitter(authConfig));
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.tv_username);
loginButton = (TwitterLoginButton) findViewById(R.id.twitter_login_button);
loginButton.setCallback(new Callback<TwitterSession>() {
#Override
public void success(Result<TwitterSession> result) {
// The TwitterSession is also available through:
// Twitter.getInstance().core.getSessionManager().getActiveSession()
Log.d("Twitter ", "Login sucessfull");
session = result.data;
String username = session.getUserName();
userid = session.getUserId();
textView.setText("Hi " + username);
TwitterAuthToken authToken = session.getAuthToken();
String token = authToken.token;
String secret = authToken.secret;
// TODO: Remove toast and use the TwitterSession's userID
// with your app's user model
String msg = "#" + session.getUserName() + " logged in! (#" + session.getUserId() + ")";
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
TweetComposer.Builder builder = new TweetComposer.Builder(MainActivity.this).text("test tweet 789");
builder.show();
getUserData();
}
#Override
public void failure(TwitterException exception) {
Log.d("TwitterKit", "Login with Twitter failure", exception);
}
});
}
Silently posting tweets doesn't seem to be part of Fabric's SDK. You may want to look at their REST API.

Neither Fabric for Android nor twitter4j find tweets containing a specific user's mention

I'm trying to retrieve tweets that mention an specific user either using fabric for android or twitter4j, but I'm not getting anything.
-With Fabric for Android I'm doing it with "twitterApiClient.getSearchService().tweets" (logged in as a guest previously)
-With twitter4j, this is my code:
public List<Long> twList (String user){
List<Long> listTw = new ArrayList<>();
lastID = Long.MAX_VALUE;
int tamano = 0;
ArrayList<Status> tweets = new ArrayList<Status>();
String mention = "#"+user.trim();
query = new Query(user);
while (tweets.size() < numberOfTweets) {
tamano = tweets.size();
if (numberOfTweets - tweets.size() > 100) {
query.setCount(100);
} else {
query.setCount(numberOfTweets - tweets.size());
}
try {
QueryResult result = twitter.search(query);
tweets.addAll(result.getTweets());
Log.d("App", "Gathered " + tweets.size() + " tweets");
for (Status t : tweets) {
if (t.getId() < lastID) {
lastID = t.getId();
}
}
} catch (TwitterException te) {
Log.d("App", "Couldn't connect: " + te);
}
query.setMaxId(lastID - 1);
if (tamano == tweets.size()) break;
}
for (Status s: tweets){
if (s.getText().matches(mention)){
listTw.add(s.getId());
Log.d("App", s.getText());
}
}
tweets.clear();
return listTw;
}
When I look for the username on Twitter website, I get those tweets where it's mentioned.
Any idea?
When was the last time a Tweet including the username you're searching for, posted? The Search API (which is used by both Fabric and Twitter4j) only covers around 7 days of data. The website has the complete archive, but that is not available in the public Twitter API.

How to Login linkedin in android?

I am building an android application where user will login using linkedin.
When user click on the button the default linkedin login page appear after entering the Email ID and password when I click accepted I an disable to get user details.
Below is my login code -
public void onClick(View v) {
if (v.getId() == R.id.btnLinkedin) {
oAuthService = LinkedInOAuthServiceFactory.getInstance()
.createLinkedInOAuthService(Constants.CONSUMER_KEY,
Constants.CONSUMER_SECRET);
System.out.println("oAuthService : " + oAuthService);
factory = LinkedInApiClientFactory.newInstance(
Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET);
liToken = oAuthService
.getOAuthRequestToken(Constants.OAUTH_CALLBACK_URL);
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(liToken
.getAuthorizationUrl()));
Toast.makeText(getApplicationContext(), "3", Toast.LENGTH_LONG).show();
startActivity(i);
}
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Toast.makeText(getApplicationContext(), "", Toast.LENGTH_LONG).show();
try {
linkedInImport(intent);
} catch (NullPointerException e) {
e.printStackTrace();
}
}
private void linkedInImport(Intent intent) {
String verifier = intent.getData().getQueryParameter("oauth_verifier");
System.out.println("liToken " + liToken);
System.out.println("verifier " + verifier);
LinkedInAccessToken accessToken = oAuthService.getOAuthAccessToken(
liToken, verifier);
client = factory.createLinkedInApiClient(accessToken);
// client.postNetworkUpdate("LinkedIn Android app test");
Person profile = client.getProfileForCurrentUser(EnumSet.of(
ProfileField.ID, ProfileField.FIRST_NAME,
ProfileField.LAST_NAME, ProfileField.HEADLINE));
System.out.println("First Name :: " + profile.getFirstName());
System.out.println("Last Name :: " + profile.getLastName());
System.out.println("Head Line :: " + profile.getHeadline());
}
LinkedIn now provides an Android development SDK to handle these situations for you more easily, that you might want to look into:
https://developer.linkedin.com/docs/android-sdk
I know this is an old thread, but just in case anyone came here looking for answers...
LinkedIn has deprecated and stopped supporting their old mobile SDKs as per this link, so I've created a lightweight "unofficial" SDK for Android, you can use it from this GitHub repo.
We also use it in our production apps, so it should be working fine. :)

android twitter

i am developing and application in which i want to get some feeds from twitter like picture, name, tweets, time and number of reply on each tweet. i did all but could not get number of reply for each tweet.... help me out thanks in advance..
i am posting my code also.
Twitter unauthenticatedTwitter = new TwitterFactory().getInstance();
Paging paging = new Paging(1, 100);
List<twitter4j.Status> statuses = unauthenticatedTwitter.getUserTimeline("BeingSalmanKhan",paging);
for (Status status3 : statuses)
{
TwitterFeeds tFeeds = new TwitterFeeds();
System.out.println(status3.getText());
tFeeds.strTweet = status3.getText();
tFeeds.strDate = status3.getCreatedAt().toString();
System.out.println("---------------------------------- " + status3.getSource());
al_tweets.add(tFeeds);
}
str_tw_name = unauthenticatedTwitter.showUser("BeingSalmanKhan").getName();
str_tw_imgurl = unauthenticatedTwitter.showUser("BeingSalmanKhan").getProfileImageURL().toString();
bitmap_twpic = NewsActivity.DownloadImage(str_tw_imgurl);
Try this snippet of code... it worked for me.. hope for you too
try {
Twitter unauthenticatedTwitter = new TwitterFactory().getInstance();
//URLEntity[] uent=
//First param of Paging() is the page number, second is the number per page (this is capped around 200 I think.
Paging paging = new Paging(1, 100);
List<twitter4j.Status> statuses = unauthenticatedTwitter.getUserTimeline("ashabhosle",paging);
System.out.println("status no 2 ="+statuses.get(2).toString());
long retweetcnt=statuses.get(2).getRetweetCount();
System.out.println("retweet count on 2nd tweet "+retweetcnt);
for (Status status3 : statuses)
{
System.out.println(status3.getText());
}
}
catch (Exception e) {
e.printStackTrace();
System.out.println("Failed to get timeline: " + e.getMessage());
}
try getRelatedResults(),gives a list of replies + mentions,it is the closest to getting replies.

EasyFacebook Android SDK - how do I get user photo?

I followed this tutorial http://kodefun.junian.net/2011/10/easy-facebook-android-sdk-simple.html and managed to successfully connect to facebook.
But how do I get user photos? Here's the code so far:
...
public void loginSuccess(Facebook facebook) {
GraphApi graphApi = new GraphApi(facebook);
User user = new User();
try{
user = graphApi.getMyAccountInfo();
//update your status if logged in
graphApi.setStatus("Hello, world!");
} catch(EasyFacebookError e){
Log.d("TAG: ", e.toString());
}
fbLoginManager.displayToast("Hey, " + user.getFirst_name() + "! Login success!");
List<Photo> listPh = graphApi.getAllPhotosMy();
Photo ph = listPh.get(0);
/// ... how do I get a user photo to drawable or something?
}
...
Any ideas? :) Thanks!
Just from messing around in there reference, I would say you would get the persons's ID and the feed that into a from, and then feed that from into the photo again.
I'm no expert on this, but there documentation is your friend.
http://www.easyfacebookandroidsdk.com/doc/index.html

Categories

Resources