Skip to content

Instantly share code, notes, and snippets.

@balazsnemeth
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balazsnemeth/0485c91472d6c78d0006 to your computer and use it in GitHub Desktop.
Save balazsnemeth/0485c91472d6c78d0006 to your computer and use it in GitHub Desktop.
Post to Twitter
- (void)sendTweetWithExperienceInfo:(NSDictionary*)info withCompletion:(void(^)(NSError *error))completion
{
//Create basic post info.
NSString *status = [self tweetWithDescrition:[expInfo objectForKey:@"statusMessage"] withHeyLetsShortURL:expInfo[@"url"]];
__block NSMutableDictionary *message = [@{
@"status": status,
} mutableCopy];
//if location info is presented, lets add them to the post.
if (expInfo[@"lat"]) {
message[@"lat"] = expInfo[@"lat"];
}
if (expInfo[@"lon"]) {
message[@"long"] = expInfo[@"lon"];
}
id image = [expInfo objectForKey:@"image"];
if (image) {
//Image is presented, let's upload it
__weak typeof(self) weakSelf = self;
[self sendTweetWithImage:image withCompletion:^(NSNumber *mediaID, NSError *error) {
if (error) {
completion (error);
return;
}
if (mediaID) {
//Connect media ID to the tweet!
[message setObject:mediaID.stringValue forKey:@"media_ids"];
[message setObject:@"1" forKey:@"trim_user"];
}
//Post the media
[weakSelf postTwitterStatus:message withCompletion:completion];
}];
}
else {
[self postTwitterStatus:message withCompletion:completion];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment