iosobjective-ctwittersocial-framework

Is it possible to do a retweet from within an app via API?


I'm making an iPhone app where I get all feeds of a certain user. Now I was wondering if it's possible to do a retweet when you push a button? I'm using the social framework. After some searching through the social framework API, I didn't found anything.


Solution

  • Apple's limited Twitter API doesn't seem to cover retweets.
    To retweet in iOS you would need to use Twitter's API It looks like you would need to send the POST request yourself and it would look something like http://api.twitter.com/1/statuses/retweet/3962807808.json // Taken from API page.

    I've also found this SO post, but there doesn't seem to be an accepted answer How to implement RETWEET in ios 5?

    Here's some sample code for retweeting from Cocoanetics

    - (void)_retweetMessage:(TwitterMessage *)message
    {
        NSString *retweetString = [NSString stringWithFormat:@"http://api.twitter.com/1/statuses/retweet/%@.json", message.identifier];
        NSURL *retweetURL = [NSURL URLWithString:retweetString];
        TWRequest *request = [[TWRequest alloc] initWithURL:retweetURL parameters:nil requestMethod:TWRequestMethodPOST];
        request.account = _usedAccount;
    
        [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
            if (responseData)
            {
                NSError *parseError = nil;
                id json = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&parseError];
    
                if (!json)
                {
                    NSLog(@"Parse Error: %@", parseError);
                }
                else
                {
                    NSLog(@"%@", json);
                }
            }
            else
            {
                NSLog(@"Request Error: %@", [error localizedDescription]);
            }
        }];
    }
    

    EDIT: Keab42 pointed out the link is for the Twitter API which will be deprecated early next year. Here's the updated API page. https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/%3Aid