简体   繁体   English

MGTwitterEngine和iPhone

[英]MGTwitterEngine and iPhone

I downloaded MGTwitterEngine and added to my iPhone project. 我下载了MGTwitterEngine并添加到我的iPhone项目中。 It's connecting and getting statues I can tell from dumping them into an NSLog. 它可以连接并获取可以将它们转储到NSLog中的雕像。 But, I can't figure out how how I need to parse the calls so I can add them to a table. 但是,我无法弄清楚我需要如何解析调用,以便将它们添加到表中。 They are returned as an NSString and look like this: 它们作为NSString返回,如下所示:

      {
    "created_at" = 2009-07-25 15:28:41 -0500;
    favorited = 0;
    id = 65;
    source = "<a href=\"http://twitter.com/\">Twitter</a>";
    "source_api_request_type" = 0;
    text = "The wolf shirt strikes again!! #sdcc :P http://twitpic.com/blz4b";
    truncated = 0;
    user =         {
        "created_at" = "Sat Jul 25 20:34:33 +0000 2009";
        description = "Host of Tekzilla on Revision3 and Qore on PSN. Also, a geek.";
        "favourites_count" = 0;
        "followers_count" = 0;
        following = false;
        "friends_count" = 0;
        id = 5;
        location = "San Francisco";
        name = "Veronica Belmont";
        notifications = false;
        "profile_background_tile" = false;
        "profile_image_url" = "http://blabnow.com/avatar/Twitter_10350_new_twitter_normal.jpg";
        protected = 0;
        "screen_name" = Veronica;
        "statuses_count" = 2;
        "time_zone" = UTC;
        url = "http://www.veronicabelmont.com";
        "utc_offset" = 0;
    };

Anybody used this that can tell me how everyone else uses it in their project? 有人用这个可以告诉我其他人在他们的项目中如何使用它吗?

Thanks 谢谢

What you are seeing in your console is an NSLog of an NSDictionary and not an NSString. 您在控制台中看到的是NSDictionary的NSLog而不是NSString。 From Matt Gemmell's MGTwitterEngine Readme : 来自Matt Gemmell的MGTwitterEngine自述文件

The values sent to these methods are all NSArrays containing an NSDictionary for each status or user or direct message, with sub-dictionaries if necessary (for example, the timeline methods usually return statuses, each of which has a sub-dictionary giving information about the user who posted that status). 发送到这些方法的值都是包含每个状态或用户或直接消息的NSDictionary的NSArrays,必要时包含子字典(例如,时间轴方法通常返回状态,每个状态都有一个子字典,提供有关发布该状态的用户)。

So whatever object you passed to your NSLog() statement is actually a dictionary and you can access the fields with a call to: 因此,无论您传递给NSLog()语句的对象实际上是一个字典,您都可以通过以下方式访问字段:

NSString *createdAtDate = [record valueForKey:@"created_at"];
NSString *source = [record valueForKey:@"source"];
// etc...

Where record is the object. 记录是对象的地方。 Keep in mind that the user field is a sub-dictionary. 请记住, 用户字段是子字典。 You access it this way: 你这样访问它:

NSDictionary *userDict = [record valueForKey:@"user"];
NSString *name = [userDict valueForKey:@"name"];
NSString *location = [userDict valueForKey:@"location"];
// etc...

You could actually use the NSArray returned in the request as your table view's data source and then just extract the one you need by the index in your -cellForRowAtIndexPath table view delegate. 实际上,您可以将请求中返回的NSArray用作表视图的数据源,然后在-cellForRowAtIndexPath表视图委托中提取索引所需的那个。

Best Regards, 最好的祝福,

For anyone else who might find their way here, here's one way to parce the results. 对于其他可能在这里找到自己的方式的人来说,这是分析结果的一种方法。 (From a newbie, so don't count of this being the standard or even correct way) (来自新手,所以不要指望这是标准甚至是正确的方式)

The key (pun intended :D) is to use the dictionary in the appropriate delegate method. 密钥(双关语:D)是在适当的委托方法中使用字典。 Check out Matt Long's example code in another thread on the topic. 查看Matt Long在该主题的另一个主题中的示例代码。

To parce something like this: 要做这样的事情:

[myTwitterEngine getSearchResultsForQuery:@"#ironsavior"];

His example is this, in the delegate method: 他的例子就是这个,在委托方法中:

- (void)searchResultsReceived:(NSArray *)searchResults 
                   forRequest:(NSString *)connectionIdentifier
{
    if ([searchResults count] > 0)
    {
        NSDictionary *result = [searchResults objectAtIndex:0];

        NSString *fromUser = [result valueForKey:@"from_user"];
        NSString *fromUserID = [result valueForKey@"from_user_id"];
        // ...
        NSString *text = [result valueForKey@"text"];

        NSLog(@"User %@(%@): %@", fromUser, fromUserID, text);
    }
}

This would give you a very simple message that goes "User username(userid): message". 这将为您提供一条非常简单的消息“User username(userid):message”。

I'm not sure what the best way to proceed would be, I'm thinking returning a dictionary or an array that you could use elsewhere in your implementation. 我不确定最好的方法是什么,我正在考虑返回一个你可以在实现中使用的字典或数组。 Or just return the original array and parse it elsewhere. 或者只返回原始数组并在其他地方解析它。

Check out that other thread for more info. 查看其他线程以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM