Reputation: 101
I am trying to retrieve the text from every tweet of a user. I don't send a get request. I successfully connect with a tweeter account to my app with :
activity.client.authorize(activity, new Callback<TwitterSession>()
{
@Override
public void success(Result<TwitterSession> result)
{
Toast.makeText(getApplicationContext(), "Login worked", Toast.LENGTH_LONG).show();
writeInfile(result);
}
@Override
public void failure(TwitterException e)
{
Toast.makeText(getApplicationContext(), "Login failed", Toast.LENGTH_LONG).show();
}
});
With the result I can access informations from my user such as his id or his name.
I also have the UserTimeLine
final UserTimeline userTimeline = new UserTimeline.Builder()
.userId(result.data.getUserId())
.build();
How can I get his tweets or the id of his tweets from there ?
Thank you
Upvotes: 1
Views: 696
Reputation: 101
I managed to do it by looking at every methods given by auto completion so if it can help anyone, here is how I did it :
void writeData(ContentResolver contentResolver)
{
activity.client.authorize(activity, new Callback<TwitterSession>()
{
@Override
public void success(Result<TwitterSession> result)
{
writeInfile(result);
}
@Override
public void failure(TwitterException e)
{
Log.e("Twitter Log in", e.toString());
}
});
}
void writeInFile(Result<TwitterSession> result)
{
userTimeline = new UserTimeline.Builder()
.userId(result.data.getUserId())
.includeRetweets(false)
.maxItemsPerRequest(200)
.build();
userTimeline.next(null, callback);
}
Callback<TimelineResult<Tweet>> callback = new Callback<TimelineResult<Tweet>>()
{
@Override
public void success(Result<TimelineResult<Tweet>> searchResult)
{
List<Tweet> tweets = searchResult.data.items;
for (Tweet tweet : tweets)
{
String str = tweet.text; //Here is the body
maxId = tweet.id;
}
if (searchResult.data.items.size() == 200)
userTimeline.previous(maxId, callback);
else
closeOutputFile();
}
@Override
public void failure(TwitterException error)
{
//Do something
}
};
Upvotes: 2