Hi,
Today I needed implement a new custom class to Fabric for read the tweets of a public list because it doesn’t have native support for this call. Here are the steps to follow:
1 - Implement a new interface for make the query following the retrofit and the Twitter REST API instructions. In my case, I only need the slug of the list, the owner_screen_name and the count of tweets, but you can add all the parameters of the Twitter REST API. In this case I named it “ListService.java”:
{
public interface ListService {
@GET("/1.1/lists/statuses.json")
public void statuses(@Query("slug") String slug, @Query("owner_screen_name") String owner_screen_name, @Query("count") int count, Callback<List<Tweet>> cb);
}
2 - The next step is create a Custom Api Client that let us make a call to this Service. For this purpose we create a class that extends TwitterApiClient and we pass to the constructor an AppSession (guest session because we only need to read a public list):
{
public class TwitterApiList extends TwitterApiClient {
public TwitterApiList(AppSession session) {
super(session);
}
public ListService getListService() {
return getService(ListService.class);
}
}
3 - And for make the call when you need to get those tweets:
{
final TwitterApiList apiClient = new TwitterApiList(guestAppSession);
apiClient.getListService().statuses("list-slug", "owner-of-the-list", 10, new Callback<List<Tweet>>() {
@Override
public void success(Result<List<Tweet>> listResult) {
final List<Tweet> tweets = listResult.data;
// Do something with the list
}
@Override
public void failure(TwitterException e) {
// FAIL
}
});
That’s all! In the same way, we can add whatever request that there is not in the Fabric Twitter Kit.