我从TwitterKit消耗了很少的api。我想获取用户的家庭时间线,用户将在其中看到来自其关注者的推文列表。如果我们检查home timeline的api文档,则参数是可选的。现在twitter kit提供了所有必需的东西。我找到了通过Twitter工具包访问家庭时间线api的方法,但问题是它总是返回400。如果您注意到即使参数是可选的,我也必须传递它们。找到下面的代码。
Twitter工具包中的实际方法
/**
* Returns a collection of the most recent Tweets and retweets posted by the authenticating user
* and the users they follow. The home timeline is central to how most users interact with the
* Twitter service.
* <p>
* The Twitter REST API goes back up to 800 tweets on the home timeline.
* It is more volatile for users that follow many users or follow users who Tweet frequently.
*
* @param count (optional) Specifies the number of tweets to try and retrieve, up to a maximum
* of 200. The value of count is best thought of as a limit to the number of tweets
* to return because suspended or deleted content is removed after the count has
* been applied. We include retweets in the count, even if include_rts is not
* supplied. It is recommended you always send include_rts=1 when using this API
* method.
* @param sinceId (optional) Returns results with an ID greater than (that is, more recent than)
* the specified ID. There are limits to the number of Tweets which can be
* accessed through the API. If the limit of Tweets has occurred since the
* since_id, the since_id will be forced to the oldest ID available.
* @param maxId (optional) Returns results with an ID less than (that is, older than) or equal
* to the specified ID.
* @param trimUser (optional) When set to either true, t or 1, each Tweet returned in a timeline
* will include a user object including only the status authors numerical ID.
* Omit this parameter to receive the complete user object.
* @param excludeReplies (optional) This parameter will prevent replies from appearing in the
* returned timeline. Using exclude_replies with the count parameter will
* mean you will receive up-to count tweets — this is because the count
* parameter retrieves that many tweets before filtering out retweets and
* replies. This parameter is only supported for JSON and XML responses.
* @param contributeDetails (optional) This parameter enhances the contributors element of the
* status response to include the screen_name of the contributor. By
* default only the user_id of the contributor is included.
* @param includeEntities (optional) The entities node will be disincluded when set to false.
*/
@GET("/1.1/statuses/home_timeline.json?" +
"tweet_mode=extended&include_cards=true&cards_platform=TwitterKit-13")
Call<List<Tweet>> homeTimeline(@Query("count") Integer count,
@Query("since_id") Long sinceId,
@Query("max_id") Long maxId,
@Query("trim_user") Boolean trimUser,
@Query("exclude_replies") Boolean excludeReplies,
@Query("contributor_details") Boolean contributeDetails,
@Query("include_entities") Boolean includeEntities);
我必须称之为
val homeTimeline = TwitterCore.getInstance().apiClient.statusesService.homeTimeline(100, 344796632681967616, Long.MAX_VALUE, true, false, false, false)
homeTimeline.enqueue(object : Callback<List<Tweet>>() {
override fun success(result: Result<List<Tweet>>) {
toast(result.data?.size.toString())
}
override fun failure(exception: TwitterException) {
toast(exception.message.toString())
}
})
如果我遗失任何东西,有人可以指导我吗?消费者和秘密密钥配置正确,因为我已经可以接收用户时间线。