2012-05-15 68 views
1

我只想获取特定Twitter帐户的所有推文。我想使用下面的url,但不知道我们如何获得twitter帐户的user_id或screen_name,我们想要获取它的推文。获取特定Twitter帐户的所有推文?

资源URL http://api.twitter.com/1/statuses/user_timeline.format参数在请求用户时间轴时,始终指定user_id或screen_name。

有没有人有任何想法或源代码或参考。任何帮助将是非常可观的。

我使用下面的函数用于获取200个鸣叫,但它示出了的NSLog

HTTP响应状态:403消息

功能

- (IBAction)followOnTwitter:(id)sender 
{ 
    ACAccountStore *accountStore = [[ACAccountStore alloc] init]; 

    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 

    [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(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]; 

       NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init]; 
       [tempDict setValue:@"rohit40793982" forKey:@"screen_name"]; 
       //[tempDict setValue:@"true" forKey:@"follow"]; 
       // [tempDict setValue:@"683286" forKey:@"user_id "]; 

       TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"http://api.twitter.com/1/statuses/user_timeline.format"] 
                  parameters:tempDict 
                  requestMethod:TWRequestMethodPOST]; 


       [postRequest setAccount:twitterAccount]; 

       [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
        NSLog(@"%@",urlResponse); 
        tweets = [NSJSONSerialization JSONObjectWithData:responseData 
                  options:kNilOptions 
                   error:&error]; 
        NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]]; 
        NSLog(@"%@", output); 
        [self performSelectorOnMainThread:@selector(displayText:) withObject:output waitUntilDone:NO]; 

       }]; 
      } 
     } 
    }]; 
} 

我无法接收的阵列所有推文。

回答

3

你的错,我认为是用这条线

http://api.twitter.com/1/statuses/user_timeline.format 

“.format”是你想要的响应格式。例如,如果你想XML,使用

https://api.twitter.com/1/statuses/user_timeline.xml 

或JSON,使用

https://api.twitter.com/1/statuses/user_timeline.json 

您还需要将SCREEN_NAME追加为查询。例如,要将我的所有推文作为JSON获取,请使用

https://api.twitter.com/1/statuses/user_timeline.xml?screen_name=edent 
1

screen_name基本上就是帐号名称。这是'@'之后的名字。像WOW的screen_name是@Warcraft。

哦,其实.format是问题所在。您必须指定3:atom,json或xml中的一个。 (我认为,让用户时间表不允许XML返回,只读过API)

由于我是一个Java程序员恐怕我不能帮助任何进一步的:/

+0

您是否可以再次查看我编辑的内容。 –

+0

由于最近的Twitter更改,json是目前唯一可用的格式:https://dev.twitter.com/docs/api/1.1/overview#New_Twitter_client_policies – alairock

相关问题