使用TwitterApiClient类Android应用程序制作的REST API调用 [英] Making REST API calls from an Android app using TwitterApiClient class
问题描述
我使用Twitter的面料SDK在我的Android应用程序。我必须获得一个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();
做一个请求机制类似于所有的服务,这里是从<一个搜索的例子href="https://github.com/twitterdev/cannonball-android/blob/master/app/src/main/java/io/fabric/samples/cannonball/activity/PoemPopularActivity.java"相对=nofollow>炮弹示例应用程序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;
}
}
);
这篇关于使用TwitterApiClient类Android应用程序制作的REST API调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!