0

在我的应用程序中,我想在未登录 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];
         }
     }

 }];
}
4

2 回答 2

0

尝试这个:

NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
ACAccount *twitterAccount = [arrayOfAccounts lastObject];

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

postRequest.account = twitterAccount;
于 2014-02-15T17:49:29.590 回答
0

检查响应。肯定是

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

于 2013-02-04T06:05:12.570 回答