MGTwitterEngine - 最喜欢的推文

发布于 2024-10-12 14:12:03 字数 215 浏览 7 评论 0原文

我正在尝试使用 MGTwitterEngine 收藏一条推文,

我正在使用“Tweet”,这是我制作的一个子类,用于处理用户 ID、名称等。因此,我将其放入一个字符串中,然后将其转换为可用于处理最喜欢的行为。推文

我的代码:http://pastie.org/1467311

I am attempting to favorite a tweet using MGTwitterEngine

I am using "Tweet" a sub-class I made which handles the user ids, names, etc. So I put that into a string which then gets converted to a number that can be used to handle the act of fav. a tweet

My Code: http://pastie.org/1467311

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲世九天 2024-10-19 14:12:03

这是一篇非常古老的帖子,不确定是否有人在寻找它,但在经历了一些“偶然”之后,我今天成功地做到了这一点。您需要执行以下操作:

  1. 声明您的类实现 MGTwitterEngineDelegate
  2. 至少实现以下方法来获取状态

    (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier
    
  3. statuses 数组的第一个位置有一个 NSDictionary。提取如下

    NSDictionary *status = (NSDictionary *)[statuses objectAtIndex:0];
    
  4. 从字典“source_api_request_type”和“id”中提取两个键。将它们都保存为 NSString 值。

  5. 更新 MGTwitterEngine.h 和 MGTwitterEngine.m 以更改 markUpdate 方法的方法签名,将 updateID 作为 NSString 而不是 unsigned int 发送。更改后它将类似于以下内容:

    (NSString *)markUpdate:(NSString *)updateID asFavorite:(BOOL)flag; // 收藏夹/创建、收藏夹/销毁
    
  6. 将 markUpdate 方法中的 %u 更改为 %@,以便正确应用输入参数更改。 (您必须在方法中的两个地方进行更改)

  7. 回到代码中,您将使用类似于以下内容的内容来发送推文。

    [twitterEngine sendUpdate: @"我的推文文本"]; 
    
  8. 一旦推文成功发布,这将引发 statusRecieved 事件。在前面提到的 statusRecieved 事件中,我们需要两个值:tweetId 和请求类型。

  9. 使用以下代码检查 request Type == 5 是否存在,如果是,则通过传递 tweet Id 值和布尔值 YES 来收藏该推文(或 NO 来取消收藏)来调用 markUpdate 方法。您的代码将如下所示:

    (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier
    {
        if([状态计数] > 0)
        {
            NSDictionary *status = (NSDictionary *)[statuses objectAtIndex:0];
            NSString *stringId = (NSString *)[status objectForKey:@"id"];
            NSNumber *requestType = (NSNumber *)[status objectForKey:@"source_api_request_type"];
            NSLog(@"推文 ID 字符串 - %@ 和请求类型:%@。", stringId, requestType);
            if ([requestType isEqualToNumber: [NSNumber numberWithInt: 5]])
            {
                [twitterEngine markUpdate: stringId asFavorite:YES];
            }
        }
    }
    
  10. “请求类型”5 的秘密在于,新推文发布的“api 请求 id”为 5,并且我们希望将新推文仅标记为最喜欢的。 (当您在推文被标记为收藏后查看 id 时,它的状态将是 26)。

随着 iOS 5 的临近,MGTwitterEngine 将很快被弃用。但在我自己的项目中解决这个问题对我来说很有趣。希望有人觉得它有用。

This is a very old post and not sure if anyone is looking out for it, but I managed to do this exact thing today after some 'hit-and-miss'. Here is what you have to do:

  1. Declare your class implements the MGTwitterEngineDelegate
  2. Implement atleast the following method to get status

    (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier
    
  3. The statuses array has a NSDictionary at the first position. Extract it as follows

    NSDictionary *status = (NSDictionary *)[statuses objectAtIndex:0];
    
  4. Extract two keys from the Dictionary "source_api_request_type" and "id". Save both of them as NSString values.

  5. Update the MGTwitterEngine.h and MGTwitterEngine.m to change method signature of the markUpdate method to send the updateID as a NSString instead of unsigned int. It will look similar to the following after change:

    (NSString *)markUpdate:(NSString *)updateID asFavorite:(BOOL)flag; // favorites/create, favorites/destroy
    
  6. Change the %u in markUpdate method to %@ so that the input parameter change applies correctly. (You have to make the change at two places in the method)

  7. Back in your code you will use something similar to the following to send the tweet.

    [twitterEngine sendUpdate: @"My Tweet Text"]; 
    
  8. This will raise the statusRecieved event once the tweet is posted successfully. In statusRecieved event as mentioned earlier we need two values the tweetId and the request type.

  9. Use the following code to check if request Type == 5, and if it is call the markUpdate method by passing the values the tweet Id and boolean value of YES to favorite (or NO to un-favorite) the tweet. Your code will look like this:

    (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier
    {
        if([statuses count] > 0)
        {
            NSDictionary *status = (NSDictionary *)[statuses objectAtIndex:0];
            NSString *stringId = (NSString *)[status objectForKey:@"id"];
            NSNumber *requestType = (NSNumber *)[status objectForKey:@"source_api_request_type"];
            NSLog(@"Tweet ID String - %@ and Request Type: %@.", stringId, requestType);
            if ([requestType isEqualToNumber: [NSNumber numberWithInt: 5]])
            {
                [twitterEngine markUpdate: stringId asFavorite:YES];
            }
        }
    }
    
  10. The secret sauce of 'request type' 5 is that a new tweet posting has 'api request id' of 5 and we want want to mark new tweets as favorite only. (When you watch the id after the tweet is marked favorite it will be status 26).

With iOS 5 looming MGTwitterEngine will soon be deprecated. But it was fun for me to figure this out in my own project. Hope someone finds it useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文