【问题标题】:not able to getting the twitter home time line tweets无法获取 twitter 主页时间线推文
【发布时间】:2013-01-18 19:08:10
【问题描述】:

在我的应用程序中,我想在未登录 twitter 帐户进入 iPhone 的设置时从 twitter 获取推文。实际上我只收到用户推文(我发推文)。但我想获得所有关注者的推文。

我正在使用这个网址:http://api.twitter.com/1/statuses/user_timeline.json

我改为:http://api.twitter.com/1/statuses/home_timeline.json 发生错误。 错误是:由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“* -[__NSArrayM insertObject:atIndex:]: object cannot be nil”

我正在使用此代码。

- (IBAction)twitterButtonPressed:(UIButton *)sender
{
    [self.usernameTextField resignFirstResponder];
    self.nameString = self.usernameTextField.text;
    NSURL *timelineUrl = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/home_timeline.json"];

    NSMutableDictionary *parameters =
    [[NSMutableDictionary alloc] init];
    [parameters setObject:self.nameString forKey:@"screen_name"];
    [parameters setObject:@"50" forKey:@"count"];
    [parameters setObject:@"1" forKey:@"include_entities"];

    SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:timelineUrl parameters:parameters];

    [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
     {
         if (responseData != nil)
         {
             NSError *error = nil;
             self.dataSource = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];

         NSLog(@" tweet inindex 0 %@",[self.dataSource valueForKey:@"text"]);

         NSLog(@"ghjgjhdgjhdgjsgdjgsdjg  %d",dataSource.count);

             if (self.dataSource.count)
             {
             [self performSelectorOnMainThread:@selector(homeView) withObject:nil waitUntilDone:YES];
         }
     }

 }];
}

【问题讨论】:

    标签: iphone ios objective-c twitter ios6


    【解决方案1】:

    检查响应。应该是

    NSLog(@"%@",[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error]);
    

    响应可能是

    {
        errors =     (
                    {
                code = 215;
                message = "Bad Authentication data";
            }
        );
    }
    

    因为主页时间线需要身份验证。

    查看如何使用 iOS 5 获取 twitter

    https://dev.twitter.com/docs/ios/making-api-requests-twrequest

    但用户必须在 twitter 上登录。

    如果您不想使用 iOS 5 twitter,请尝试使用其他带有 oAuth 的库,例如 https://github.com/bengottlieb/Twitter-OAuth-iPhone

    【讨论】:

      【解决方案2】:

      试试这个:

      NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
      ACAccount *twitterAccount = [arrayOfAccounts lastObject];
      
      SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:requestURL parameters:parameters];
      
      postRequest.account = twitterAccount;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-09-13
        • 2015-08-27
        • 1970-01-01
        • 1970-01-01
        • 2014-09-30
        • 2012-02-06
        • 2018-03-15
        • 1970-01-01
        相关资源
        最近更新 更多