使用TwitterApiClient类Android应用程序制作的REST API调用应用程序、Android、TwitterApiClient、REST

2023-09-07 01:11:31 作者:没那资本让你死心踏地

我使用Twitter的面料SDK在我的Andr​​oid应用程序。我必须获得一个Twitter用户的鸣叫和放大器;状态信息。我一直没能找到任何的例子,该文档是不是对这个很清楚,所以我已经发布了一个新问题。有人可以提供一个如何使用 TwitterApiClient 类的例子吗?

I'm using Twitter's Fabric SDK in my Android app. I have to acquire a Twitter user's Tweets & Status Messages. I have not been able to find any examples, and the documentation is not very clear on this, so I have posted a new question. Can someone provide an example of how to use the TwitterApiClient class ?

推荐答案

Twitter的工具包已经使API调用的能力。官方的文档是在这里: https://dev.twitter.com/twitter-kit/android / API

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

一切始于状态的服务:

StatusService service = Twitter.getApiClient().getStatusesService()

可用一些方法在状态服务(这些方法都直接映射到REST API端点,包括参数。

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();

做一个请求机制类似于所有的服务,这里是从炮弹示例应用程序code :

final SearchService service = Twitter.getApiClient().getSearchService();

service.tweets(SEARCH_QUERY, null, null, null, SEARCH_RESULT_TYPE, SEARCH_COUNT, null, null,
            maxId, true, new Callback<Search>() {
                @Override
                public void success(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;
                }

                @Override
                public void failure(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;
                }
            }
);
 
精彩推荐