Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. - (IBAction)shareOGStoryWithShareDialog:(id)sender
  2. {
  3. // Retrieve a picture from the device's photo library
  4. /*
  5. NOTE: SDK Image size limits are 480x480px minimum resolution to 12MB maximum file size.
  6. In this app we're not making sure that our image is within those limits but you should.
  7. Error code for images that go below or above the size limits is 102.
  8. */
  9. UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
  10. [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
  11. [imagePicker setDelegate:self];
  12. [self presentViewController:imagePicker animated:YES completion:nil];
  13.  
  14. }
  15.  
  16.  
  17. // When the user is done picking the image
  18. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info
  19. {
  20.  
  21. /// Package the image inside a dictionary
  22. NSArray* image = @[@{@"url": [info objectForKey:UIImagePickerControllerOriginalImage], @"user_generated": @"true"}];
  23.  
  24. // Create an object
  25. id<FBGraphObject> object =
  26. [FBGraphObject openGraphObjectForPostWithType:@"me/sharing_opengraph:music"
  27. title:@"Test OPG"
  28. image:@"https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png"
  29. url:@"http://samples.ogp.me/419339761553169"
  30. description:@"Kelan kya kita magagawa"];
  31.  
  32. // Create an action
  33. id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
  34.  
  35. // Set image on the action
  36. [action setObject:image forKey:@"image"];
  37.  
  38. // Link the object to the action
  39. [action setObject:object forKey:@"music"];
  40.  
  41. // Tag one or multiple users using the users' ids
  42. //[action setTags:@[<user-ids>]];
  43.  
  44. // Tag a place using the place's id
  45. id<FBGraphPlace> place = (id<FBGraphPlace>)[FBGraphObject graphObject];
  46.  
  47. [place setObjectID:@"141887372509674"]; // Facebook Seattle
  48. [action setPlace:place];
  49.  
  50. // Dismiss the image picker off the screen
  51. [self dismissViewControllerAnimated:YES completion:nil];
  52.  
  53. // Check if the Facebook app is installed and we can present the share dialog
  54. FBOpenGraphActionParams *params = [[FBOpenGraphActionParams alloc] init];
  55. params.action = action;
  56. params.actionType = @"me/sharing_opengraph:hear";
  57.  
  58. // If the Facebook app is installed and we can present the share dialog
  59. if([FBDialogs canPresentShareDialogWithOpenGraphActionParams:params]) {
  60. // Show the share dialog
  61. [FBDialogs presentShareDialogWithOpenGraphAction:action
  62. actionType:@"me/sharing_opengraph:hear"
  63. previewPropertyName:@"music"
  64. handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
  65. if(error) {
  66. // An error occurred, we need to handle the error
  67. // See: https://developers.facebook.com/docs/ios/errors
  68. NSLog(@"Error publishing story: %@", error.description);
  69. } else {
  70. // Success
  71. NSLog(@"result %@", results);
  72. }
  73. }];
  74.  
  75. // If the Facebook app is NOT installed and we can't present the share dialog
  76. } else {
  77. // FALLBACK: publish just a link using the Feed dialog
  78.  
  79. UIAlertView *notInstalled = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Facebook App not Installed" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  80.  
  81. [notInstalled show];
  82.  
  83. }
  84.  
  85. }
  86.  
  87. // A function for parsing URL parameters.
  88. - (NSDictionary*)parseURLParams:(NSString *)query {
  89. NSArray *pairs = [query componentsSeparatedByString:@"&"];
  90. NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
  91. for (NSString *pair in pairs) {
  92. NSArray *kv = [pair componentsSeparatedByString:@"="];
  93. NSString *val =
  94. [kv[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  95. params[kv[0]] = val;
  96. }
  97. return params;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement