MGTwitterEngine - Fav a Tweet

删除回忆录丶 提交于 2019-12-02 06:28:48

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/4707048/mgtwitterengine-fav-a-tweet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!