2

I'm using the iOS SDK with the native dialog to try to post an object and action.

When I call presentShareDialogWithOpenGraphAction, the Facebook app opens, briefly shows the dialog with my post in it, and then returns to my app with the error:

Could not generate preview text

My code looks like this:

NSDictionary* object = @{
                         @"fbsdk:create_object": @YES,
                         @"type": @"appsterbator.app_idea",
                         @"title": @"test",
                         @"url": @"http://test.com",
                         };
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:object
           forKey:@"app_idea"];


[FBDialogs presentShareDialogWithOpenGraphAction:action actionType:@"app_idea.create"
                             previewPropertyName:@"app_idea"
                                         handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
                                          NSLog(@"%@", error);
                                      }];

Also, is it possible post an Open Graph object that doesn't actually have a URL?

Sam
  • 2,707
  • 1
  • 23
  • 32
tobyc
  • 2,237
  • 2
  • 20
  • 26
  • I see two possible problems: could it be that you use . instead of :? Second: Could it be, that the story/action is not submitted yet? – Sam Jun 03 '13 at 12:30
  • I've tried both . and : so I don't think it's that (FB examples don't seem to be consistent). You might be right about the story not being submitted though. I thought it would work if I was testing against my own account though? – tobyc Jun 03 '13 at 12:39
  • I have the same problem, my i don't have access to the facebook app of my customer, so i can't sumit the action. I have to wait that it will be done by the customer. Have you subitted the action? I think you have to test it with you facebook developer account. did you do that? – Sam Jun 03 '13 at 13:11
  • inorder to submit you must test it with the developer account indeed. I'm facing the same problem, couldn't find a solution yet. How come nobody is answering this?? – David Ben Ari Jun 04 '13 at 14:26

6 Answers6

3

I had the same symptoms, but a different fix. Facebook SDK 3.5.* since the Share Dialog came out of beta.

I had a custom Object Graph story: Solve -> Puzzle. This was my first time working with OG, so this might seem obvious to someone more familiar with it, but it stalled me for long enough that I wanted to share.

I ran through the Share Dialog examples on the developer site, but the Open Graph related sharing would not work via simple copy paste. I figured because the OG objects were tied to the App ID and URL host etc. I setup my web host so that I could serve OG data for my objects, and configured my app to allow that host etc..

So I set about adapting the sample code to use the parameters present in the "opengraph / stories -> Get Code" popover. Setting the platform to iOS SDK, I got the following for Create Action:

NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
action[@"puzzle"] = @"http://samples.ogp.me/463417983744195";

[FBRequestConnection startForPostWithGraphPath:@"me/shapeshuffle:solve"
                               graphObject:action
                         completionHandler:^(FBRequestConnection *connection,
                                             id result,
                                             NSError *error) {
                             // handle the result
                         }];

I swapped my story and app specific values into the sample code, leading to the the error and symptoms described in the question. I spent longer than I care to admit fiddling with the server hosting my OG object, FB App settings, different ways of popping the share dialog etc.

The root of the problem was that on popping the dialog, FB was unable to match the action and object with the configuration in my app - hence the slightly vague error code relating to generating the preview text. FB wasn't finding the action because "me/shapeshuffle:solve" (the action string in the "Get Code" tool) doesn't resolve. If I understood all the different options available to me in the Get Code tool, I might have avoided this, but remember, all I wanted was to pop a share dialog. Seemed simple.

I worked with the Graph API explorer via this useful tutorial, and wound up with the following mapping from the strings I got from the FB tool to what actually worked:

Action: me/shapeshuffle:solve => shapeshuffle:solve

Lots of pain for 3 little characters. Here is what my finished code looks like:

NSString *objectUrl = [NSString stringWithFormat:@"%@puzzleId=%d", @"http://myhost.com/puzzle/object?", puzzleId];

id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
    [action setObject:objectUrl forKey:@"puzzle"];
    [action setObject:timeString forKey:@"time"];

[FBDialogs presentShareDialogWithOpenGraphAction:action
                                      actionType:@"shapeshuffle:solve"
                             previewPropertyName:@"puzzle"
                                         handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
                                             if(error) {
                                                 NSLog(@"Error: %@", error.description);
                                             } else {
                                                 NSLog(@"Success!");
                                             }
                                         }];
bdalziel
  • 2,005
  • 3
  • 17
  • 32
1

Had the same issue. Make sure the App Domains in Basic Info contains the oAuth domain. The odd thing I found is that in order to add this you need to enable this can only be added if you enable Page Tab or Mobile Web or one of the other options.

mdb983
  • 21
  • 2
0

I think i may know the reason that (@"url": @"http://test.com")->this may use the facebook app developer center offer.

  1. click Open Graph
  2. click Stories
  3. then you will see your custom story on right side
  4. click Get Code,then you will get the URL you need!

and (@"type": @"appsterbator.app_idea")->this may need use like this->(your_app_namespace:action_type)

Good luck!

lion
  • 1
  • 2
0

To problem with: "Could not generate preview text" come from attempts to share the same content several times. Try to change content that you share each time you check the functionality of open graph.

Eugene P
  • 554
  • 4
  • 19
0

A condition that causes this which has not been described yet is case sensitivity of the action and property name, which must be lowercase. To illustrate note the 'must_be_lowercase' in the following:

id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:@"http://link/" forKey:@"**must_be_lowercase**"];

[FBDialogs presentShareDialogWithOpenGraphAction:action
                                      actionType:@"xxxx"
                             previewPropertyName:@"**must_be_lowercase**"
                                         handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
                                             if(error) {
                                                 NSLog(@"Error: %@", error.description);
                                             } else {
                                                 NSLog(@"Success!");
                                             }
                                         }];
James Martin
  • 1,050
  • 7
  • 8
0

This is a lovely generic error message! Another possible cause I've encountered is the size of the OpenGraph image being posted.

Although Facebook documentation states images must be 200x200px to 1500x1500px, my initial attempts with a 350x350px image failed with the “Could not generate preview text” error. The same image at 600x600px on the other hand works perfectly.

-James

James Martin
  • 1,050
  • 7
  • 8