Skip to content Skip to sidebar Skip to footer

Making Rest Api Calls From An Android App Using Twitterapiclient Class

I'm using Twitter's Fabric SDK in my Android app. I need to acquire a Twitter user's Tweets & Status Messages. I have not been able to find any examples, and the documentation

Solution 1:

Twitter Kit has the ability to make API calls. The official documentation is here: https://dev.twitter.com/twitter-kit/android/api

Everything starts with Statuses Service:

StatusServiceservice= Twitter.getApiClient().getStatusesService()

Some methods available at Statuses Service (these methods have direct mapping to REST API endpoints, including the parameters.

service.homeTimeline();
service.lookup();
service.mentionsTimeline();
service.show();

The mechanism to do a request is similar to all services, here's an example of Searching from Cannonball sample app code:

finalSearchServiceservice= Twitter.getApiClient().getSearchService();

service.tweets(SEARCH_QUERY, null, null, null, SEARCH_RESULT_TYPE, SEARCH_COUNT, null, null,
            maxId, true, newCallback<Search>() {
                @Overridepublicvoidsuccess(Result<Search> searchResult) {
                    Crashlytics.setLong(App.CRASHLYTICS_KEY_SEARCH_COUNT,
                            searchResult.data.searchMetadata.count);
                    setProgressBarIndeterminateVisibility(false);
                    final List<Tweet> tweets = searchResult.data.tweets;
                    adapter.getTweets().addAll(tweets);
                    adapter.notifyDataSetChanged();
                    if (tweets.size() > 0) {
                        maxId = tweets.get(tweets.size() - 1).id - 1;
                    } else {
                        endOfSearchResults = true;
                    }
                    flagLoading = false;
                }

                @Overridepublicvoidfailure(TwitterException error) {
                    Crashlytics.logException(error);

                    setProgressBarIndeterminateVisibility(false);
                    Toast.makeText(PoemPopularActivity.this,
                            getResources().getString(R.string.toast_retrieve_tweets_error),
                            Toast.LENGTH_SHORT).show();

                    flagLoading = false;
                }
            }
);

Post a Comment for "Making Rest Api Calls From An Android App Using Twitterapiclient Class"