[英]Making REST API calls from an Android app using TwitterApiClient class
I'm using Twitter's Fabric SDK in my Android app. 我在Android应用中使用Twitter的Fabric SDK 。 I need to acquire a Twitter user's Tweets & Status Messages.
我需要获取Twitter用户的推文和状态消息。 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 ? 有人可以提供如何使用
TwitterApiClient
类的示例吗?
Twitter Kit has the ability to make API calls. Twitter Kit可以进行API调用。 The official documentation is here: https://dev.twitter.com/twitter-kit/android/api
官方文档在这里: https : //dev.twitter.com/twitter-kit/android/api
Everything starts with Statuses Service: 一切始于状态服务:
StatusService service = Twitter.getApiClient().getStatusesService()
Some methods available at Statuses Service (these methods have direct mapping to REST API endpoints, including the parameters. Statuses Service可用的一些方法(这些方法直接映射到REST API端点,包括参数。
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 : 发出请求的机制类似于所有服务,这是一个从Cannonball搜索示例应用代码的示例 :
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;
}
}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.