Last active
December 24, 2015 14:39
-
-
Save ekoneil/6813974 to your computer and use it in GitHub Desktop.
[Facebook iOS SDK example] Publish an Open Graph (OG) story that: 1/ uses image staging
2/ creates a custom, user-owned OG object
3/ creates a custom OG action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UIImage* image = [UIImage imageNamed:@"inspiration-2.jpg"]; // image stored in app's resources | |
// stage an image | |
[FBRequestConnection startForUploadStagingResourceWithImage:image | |
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { | |
if(error) { | |
NSLog(@"Error staging resource.\n%@", error); | |
int code = [[[[[error userInfo] objectForKey:@"com.facebook.sdk:ParsedJSONResponseKey"] objectForKey:@"body"] objectForKey:@"error"] objectForKey:@"code"]; | |
if(code == 2500) { | |
NSLog(@"...couldn't find an access token. Gotta log in to post stories via the API."); | |
} | |
} else { | |
NSLog(@"Successfuly staged image with staged URI: %@", [result objectForKey:@"uri"]); | |
NSString* stagedImageId = [result objectForKey:@"uri"]; | |
NSLog(@"Staged Image URI: %@", stagedImageId); | |
// configure custom, user-owned object. default audience == $app-ceiling. | |
NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPost]; | |
object.provisionedForPost = YES; | |
object[@"title"] = @"Inspiration"; | |
object[@"type"] = @"fbsdktoolkit:route"; | |
object[@"description"] = @"Mazama Inspiration route on Goat Wall"; | |
object[@"image"] = @[ | |
@{@"url": stagedImageId, @"user_generated" : @"true" } | |
]; | |
// post the object | |
[FBRequestConnection startForPostOpenGraphObject:object | |
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { | |
if(error) { | |
NSLog(@"Error: %@", error); | |
} else { | |
NSLog(@"Success. %@", result); | |
} | |
NSString* objectId = [result objectForKey:@"id"]; // read object ID from previous response | |
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject]; | |
[action setObject:objectId forKey:@"route"]; | |
// create action referencing user owned object. default audience == $app-ceiling | |
[FBRequestConnection startForPostWithGraphPath:@"/me/fbsdktoolkit:climb" | |
graphObject:action | |
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { | |
if(error) { | |
NSLog(@"Error: %@", error); | |
} else { | |
NSLog(@"Success. Created action with ID: %@", [result objectForKey:@"id"]); | |
NSLog(@"See the story at: https://www.facebook.com/{your-vanity-url}/activity/%@", [result objectForKey:@"id"]); | |
} | |
}]; | |
}]; | |
} | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@balazsnemeth Not sure if you figured it out. But from this stackoverflow answer, you can do this after line 20: