MGTwitterEngine - 发布 [英] MGTwitterEngine - Fav a Tweet

查看:78
本文介绍了MGTwitterEngine - 发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用MGTwitterEngine收藏推文



我使用Tweet我处理用户ID,名称等的子类。我把它放入一个字符串,然后转换为一个数字,可以用来处理fav的行为。 a tweet



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

解决方案

这是一个很老的帖子,不知道是否有人正在寻找它,今天做这个确切的事情后,一些打击和错过。这是您必须做的:


  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中提取两个键。


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

     (NSString *)markUpdate:(NSString *)updateID asFavorite:(BOOL)旗; //收藏/创建,收藏/销毁


  6. 更改%@ 中使用markUpdate方法中的 ,以便输入参数更改正确应用。 (您必须在方法的两个位置进行更改)


  7. 回到您的代码中,您将使用类似以下内容发送tweet。 / p>

      [twitterEngine sendUpdate:@My Tweet Text]; 


  8. 一旦发布成功,这将会引发statusRecieved事件。在前面提到的statusRecieved事件中,我们需要两个值tweetId和请求类型。


  9. 使用下面的代码检查请求类型== 5,它通过将值tweet id和布尔值YES传递给收藏夹(或不收藏)到tweet,来调用markUpdate方法。您的代码将如下所示:

     (void)statusesReceived:(NSArray *)statusRequest:(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. 的'请求类型'5是一个新的推文发布有'api请求id'为5,我们想要将新的tweets标记为仅收藏。


使用iOS 5即将推出的新功能MGTwitterEngine很快就会被弃用。但对我来说,在我自己的项目中这是很有趣。希望有人觉得有用。


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

解决方案

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.

这篇关于MGTwitterEngine - 发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆