iOS 5+:读取其他用户的 Twitter 状态/home_timeline



在我的应用程序中,我想显示来自其他用户时间线的推文。可能吗? 我可以访问不需要身份验证user_timelines但对于home_timelines我需要进行身份验证,但是我如何读取其他用户的公共时间线?

如果你想从特定用户的home_timeline中获取推文,则需要进行身份验证。 不幸的是,您最好的选择可能是授权并获取设备上的帐户。 然而,这并不是一项艰巨的任务。 以下是我在Twitter应用程序中用于请求访问该帐户的一些代码。

// Create an account store object.
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
// Create an account type that ensures Twitter accounts are retrieved.
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Request access from the user to use their Twitter accounts.
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
if(granted) {
// Get the list of Twitter accounts.
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
// For the sake of brevity, we'll assume there is only one Twitter account present.
// You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present.
if ([accountsArray count] > 0) {
// Grab the initial Twitter account to tweet from.
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
//At this point, the twitterAccount has been pulled into the *twitterAccount object.
}
}

编辑:根据下面的评论,您希望显示来自BBC的home_timeline,类似于您在 twitter.com/BBCNews 中看到的内容。 home_timeline API 调用仅返回当前经过身份验证的帐户的时间线。 这意味着您将只能获取正在使用您的应用程序的用户的时间线。

如果你想获取另一个用户的时间线,比如BBCNews,你需要使用user_timeline API调用,并在参数中指定你想要的时间线的用户,类似于选择twitterapi帐户时间线的twitter示例。

此外,从它的声音来看,user_timelineAPI 调用对您不起作用,因为您还想看到转发。 如果您查看文档,您将看到一个可选参数,您可以在 API 调用中使用该参数来include_rts该参数将包含或排除转推。

这将解决您的问题。 过去很多时候,当我使用 Twitter API 时会遇到问题时,我会问自己"我面临的问题是一个简单的问题吗? 如果您实际面临的问题确实很简单,您可以放心,问题可能已经处理或解决,只是您还没有找到解决方案。 继续破解它。user_timeline是您想要使用的,只需使用参数即可。

最新更新