【问题标题】:Twitter JSON URL for user timeline用户时间线的 Twitter JSON URL
【发布时间】:2013-03-24 17:29:48
【问题描述】:

我有一个简单的问题,在我的 iOS 应用程序中,我有 twitter 搜索 API。我正在寻找实现对 hastags 和用户时间线的搜索。对于 hastags,我有 url:http://search.twitter.com/search.json?q=%23HASHTAGHERE 但我无法找到用户时间线的 JSON url。如果有人能指出这一点,那就太好了。谢谢你

HASTAG 的电流:

NSString *urlString = [NSString stringWithFormat:@"http://search.twitter.com/search.json?q=&ands=%@&phrase=&rpp=50",searchTerm];
  NSURL *url = [NSURL URLWithString:urlString];       //Setup and start async download    

NSURLRequest *request = [[NSURLRequest 分配] initWithURL:url]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

【问题讨论】:

    标签: ios twitter hashtag


    【解决方案1】:

    用户时间线的 URL:https://api.twitter.com/1.1/statuses/user_timeline.json

    来源:https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline

    请注意,这适用于 iOS 5+,因为它使用 TWRequest

        NSURL *getTimeline = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/user_timeline.json"];
    
        NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:
                                   <twitter screen name goes here>, @"screen_name",
                                    nil];
    
        TWRequest *twitterRequest = [[TWRequest alloc] initWithURL:getTimeline
                                                        parameters:parameters
                                                     requestMethod:TWRequestMethodGET];
    
    //Set a twitter account (Gotten from iOS 5+)
        [twitterRequest setAccount:self.twitterAccount];
    
        [twitterRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
         {
             if (!error)
             {             
                 JSONDecoder *decoder = [[JSONDecoder alloc] initWithParseOptions:JKParseOptionNone];
                 NSArray *twitterTimeline = [decoder objectWithData:responseData];
    
             }
             else
             {
                 //Deal with error
             }
    
    
         }];
    

    如果您只想要一个没有任何身份验证等的 JSON 时间线,那么您可以使用: http://api.twitter.com/1/statuses/user_timeline.json?screen_name=(screen-name-here)

    【讨论】:

    • 你能举个例子吗?谢谢你。 api.twitter.com/1.1/statuses/@jayleno.json
    • 已用示例代码编辑 - 如果您需要任何进一步的帮助/说明,请查看并告诉我。干杯!
    • 我不是在寻找用户的时间线,但我希望用户能够输入任何人的姓名,然后我可以调出时间线
    • 不确定是什么问题 - 上面的代码适用于任何用户。因此,只需将您想要的名称放入 parameters 字典的 screen_name 参数中即可。只要您有权访问,您就会获得时间表。
    • 感谢您这样做,但如果您在上面看到我是如何执行此操作的,我只需使用 url。所以我得到了 getTimeline 部分,但我需要 TWRequest 部分吗?如果你在上面看到我的更新,我可以像现在一样获取一个 url 并使用 JSON。本质上,我可以使用用户的屏幕名称创建一个 url,而不是处理参数吗?谢谢。
    猜你喜欢
    • 2018-09-08
    • 2013-12-11
    • 2012-10-29
    • 1970-01-01
    • 2017-07-02
    • 2014-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多