Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (IBAction)shareOGStoryWithShareDialog:(id)sender
- {
- // Retrieve a picture from the device's photo library
- /*
- NOTE: SDK Image size limits are 480x480px minimum resolution to 12MB maximum file size.
- In this app we're not making sure that our image is within those limits but you should.
- Error code for images that go below or above the size limits is 102.
- */
- UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
- [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
- [imagePicker setDelegate:self];
- [self presentViewController:imagePicker animated:YES completion:nil];
- }
- // When the user is done picking the image
- - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info
- {
- /// Package the image inside a dictionary
- NSArray* image = @[@{@"url": [info objectForKey:UIImagePickerControllerOriginalImage], @"user_generated": @"true"}];
- // Create an object
- id<FBGraphObject> object =
- [FBGraphObject openGraphObjectForPostWithType:@"me/sharing_opengraph:music"
- title:@"Test OPG"
- image:@"https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png"
- url:@"http://samples.ogp.me/419339761553169"
- description:@"Kelan kya kita magagawa"];
- // Create an action
- id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
- // Set image on the action
- [action setObject:image forKey:@"image"];
- // Link the object to the action
- [action setObject:object forKey:@"music"];
- // Tag one or multiple users using the users' ids
- //[action setTags:@[<user-ids>]];
- // Tag a place using the place's id
- id<FBGraphPlace> place = (id<FBGraphPlace>)[FBGraphObject graphObject];
- [place setObjectID:@"141887372509674"]; // Facebook Seattle
- [action setPlace:place];
- // Dismiss the image picker off the screen
- [self dismissViewControllerAnimated:YES completion:nil];
- // Check if the Facebook app is installed and we can present the share dialog
- FBOpenGraphActionParams *params = [[FBOpenGraphActionParams alloc] init];
- params.action = action;
- params.actionType = @"me/sharing_opengraph:hear";
- // If the Facebook app is installed and we can present the share dialog
- if([FBDialogs canPresentShareDialogWithOpenGraphActionParams:params]) {
- // Show the share dialog
- [FBDialogs presentShareDialogWithOpenGraphAction:action
- actionType:@"me/sharing_opengraph:hear"
- previewPropertyName:@"music"
- handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
- if(error) {
- // An error occurred, we need to handle the error
- // See: https://developers.facebook.com/docs/ios/errors
- NSLog(@"Error publishing story: %@", error.description);
- } else {
- // Success
- NSLog(@"result %@", results);
- }
- }];
- // If the Facebook app is NOT installed and we can't present the share dialog
- } else {
- // FALLBACK: publish just a link using the Feed dialog
- UIAlertView *notInstalled = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Facebook App not Installed" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
- [notInstalled show];
- }
- }
- // A function for parsing URL parameters.
- - (NSDictionary*)parseURLParams:(NSString *)query {
- NSArray *pairs = [query componentsSeparatedByString:@"&"];
- NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
- for (NSString *pair in pairs) {
- NSArray *kv = [pair componentsSeparatedByString:@"="];
- NSString *val =
- [kv[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- params[kv[0]] = val;
- }
- return params;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement