Facebook Share Dialog on iOS: "Publish" button always greyed out - ios

I have created a custom open graph object, action and story on Facebook developer website, then followed the tutorial to be able to post it through the official FB app (without login in the app). This is the code:
NSMutableDictionary<FBGraphObject> *object;
NSString *returnUrl = [NSString stringWithFormat:#"http://tettomante.it/questions?%#",
[NSString stringWithURLParams:#{#"answer": _answerLabel.text, #"divination": [self divinationNickname]}]];
object = [FBGraphObject openGraphObjectForPostWithType:#"boobs-teller:question"
title:_questionTextView.text
image:#"https://d1rdorpdffwq56.cloudfront.net/icona_tettomante.jpg"
url:returnUrl
description:_answerLabel.text];
NSMutableDictionary<FBOpenGraphAction> *action = (NSMutableDictionary<FBOpenGraphAction> *) [FBGraphObject openGraphActionForPost];
action[#"question"] = object;
// Check if the Facebook app is installed and we can present the share dialog
FBOpenGraphActionShareDialogParams *params = [[FBOpenGraphActionShareDialogParams alloc] init];
params.action = action;
params.actionType = #"boobs-teller:ask";
params.previewPropertyName = #"question";
// If the Facebook app is installed and we can present the share dialog
if([FBDialogs canPresentShareDialogWithOpenGraphActionParams:params]) {
// Show the share dialog
[FBDialogs presentShareDialogWithOpenGraphActionParams:params
clientState:nil
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
// There was an error
NSLog(#"Error publishing story: %#", error.description);
}
else {
// Success
NSLog(#"result %#", results);
}
}];
}
The problem is that once in the FB app the custom story preview appears correctly and after about 10 seconds disappears, while the "Publish" button on the top is disabled (greyed out) and doesn't enable itself. I don't understand what's going on. I thought that could be because the app was in sandbox mode (I was using the administrator user so that shouldn't have mattered), so I made it public but nothing changed. Then I thought I had to make FB review the custom action, so I had that sorted out also, but nothing has changed. Now I don't know what to try next.

I had the same issue while creating a new app. The Open Graph tags have to be exactly correct, or you won't be able to publish your story.
Check to make sure the objects and actions created in the Facebook app dashboard match what you have listed in the code.
object = [FBGraphObject openGraphObjectForPostWithType:#"boobs-teller:question"
In this line, "boobs-teller" should be what you have listed as your App's namespace(Facebook Apps > Settings > Basic), and "questions" should be the custom Object (Open Graph > Object Types) you created in the App dashboard. If you haven't created these yet, go here: https://developers.facebook.com/apps
params.actionType = #"boobs-teller:ask";
In this line, "boobs-teller" should be your app namespace, and "ask" is the custom Action (Open Graph > Action Types) you created in the app dashboard.
More details are here: https://developers.facebook.com/docs/ios/open-graph/
You can also check the sample iOS apps on GitHub, the FBOGSampleSD app helped me out a lot while learning Open Graph. https://github.com/fbsamples/ios-howtos

Related

Facebook's "Messaging an Open Graph message" functionality keeps on returning to my app

I'm trying out Facebook's new Messaging an Open Graph message, which means one can now send open graph stories to friends via the Facebook Messenger app.
In my case, I am building an app where people create a playlist and can then invite others to contribute songs to that said playlists. Therefore, an interesting path to take is being able to post an open graph message via Facebook Messenger to one's friends.
I have set up a Create action, a Playlist object and a Create a Playlist story.
The code I use in the iOS app is very close to the one provided as an example by Facebook:
Creating the playlist object:
NSMutableDictionary<FBGraphObject> *object =
[FBGraphObject openGraphObjectForPostWithType:#"vibe-social-music:playlist"
title:#"Sample Playlist"
image:#"https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png"
url:#"http://samples.ogp.me/616101581814728"
description:#""];
Creating the action:
NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
action[#"playlist"] = object;
Creating the params:
FBOpenGraphActionParams *params = [[FBOpenGraphActionParams alloc]
initWithAction:action
actionType:#"create"
previewPropertyName:#"playlist"];
Calling the 'present message' dialog within the messenger app:
[FBDialogs
presentMessageDialogWithOpenGraphActionParams:params
clientState:nil
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if (error) {
//TODO: Handle errors
NSLog(#"error: %#", error);
} else {
NSLog(#"results: %#", results);
}
}];
As I explained before, the Facebook messenger app opens, but quickly returns back to my application.
I have the Facebook credentials well setup in my Info.plist file.
The one thing is that the action is not yet validated by Facebook. Could that be an issue?
Otherwise, I'm at a loss as to why it won't show an Open Graph story in the Messenger app, and why it always goes back to my application.
Any help would be greatly appreciated, thanks!
Can you confirm you configured a custom story in the Open Graph section of your app settings (and not just the action and object types)?
Also, it looks like the action type is missing your app namespace in the params construction: i.e.,
FBOpenGraphActionParams *params = [[FBOpenGraphActionParams alloc]
initWithAction:action
actionType:#"vibe-social-music:create"
previewPropertyName:#"playlist"];

iOS - Facebook open graph sharing via app is successful, but does not look the way I want it to on Facebook

I have an iPhone app that is used for taking photos. I just finished adding the Facebook sharing functionality to this app.
I went through this entire page here: https://developers.facebook.com/docs/ios/open-graph
I followed all of the instructions, and copied and pasted the code into xcode. The only thing I didn't do was the one part at the very bottom of the page called "Deep Linking", but that is not important right now.
After doing all of this, my app can successfully share an image to facebook. However, it is not being shared the way I need it to.
When I go to my facebook page to see the share, you would never even know it's there. I have to scroll almost half way down the page, and then it's in the bottom left corner.
Here is a screenshot showing where the share is located on my facebook page when viewed on a Desktop computer:
And here is how the share looks when using the Facebook App for the iPhone (I blacked out my name):
These both look terrible. Here are 2 examples of what I want to accomplish.
Here is how a photo from this app called "Frontback" looks when I share it to my page and view on a Desktop computer:
And it looks the same on the Facebook App for the iPhone as well.
The only difference I can tell is that the URL for my shares has "/activity/" in it, where as the Frontback app shares have "photo.php" in their Facebook URL's.
I can't figure out how to get my app's shares to look like the shares from the Frontback app.
Any help is greatly appreciated thank you.
The posts that you created seems meaningful to me. An open-graph feed is always beautiful and more meaningful than the normal feed.
What Frontback post you are seeing is simple photo upload, that's not a feed. I mean it all depends on your requirement, what exactly your app will want to do.
If you just want to show some photos via your app like Frontback, you can avoid open graph and publish photos using the API \POST /photos.
But if you want to give a link that could redirect the user to the app you should use what you are using right now.
Another thing, when you said-
When I go to my facebook page to see the share, you would never even know it's there. I have to scroll almost half way down the page, and then it's in the bottom left corner.
That's the beauty of open-graph, it clubs all the activities of an app in your timeline, not unnecessarily making status updates and flooding your timeline. The stories appear on top in your/your friends wall and the ticker. You can also see the actual story by clicking on the time in the story of your activity log-
(activity log)
(actual story)
- (void)requestPermissionAndPost {
[FBSession.activeSession requestNewPublishPermissions:[NSArray arrayWithObjects:#"publish_actions", #"publish_checkins",nil]
defaultAudience:FBSessionDefaultAudienceEveryone
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
// Now have the permission
[self postOpenGraphAction];
} else {
// Facebook SDK * error handling *
// if the operation is not user cancelled
if (error.fberrorCategory != FBErrorCategoryUserCancelled) {
[self presentAlertForError:error];
}
}
}];
}
- (void)postOpenGraphAction
{
FBRequestConnection *newConnection = [[FBRequestConnection alloc] init];
FBRequestHandler handler =
^(FBRequestConnection *connection, id result, NSError *error) {
// output the results of the request
[self requestCompleted:connection forFbID:#"me" result:result error:error];
};
UIImage *img = imageView.image;
NSString *message = [NSString stringWithFormat:#"%# %# #DealsHype",msg.text,hashtagFromStore];
FBRequest *request=[[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:#"me/photos" parameters:[NSDictionary dictionaryWithObjectsAndKeys:UIImageJPEGRepresentation(img, 0.7),#"source",message,#"message",#"{'value':'EVERYONE'}",#"privacy", nil] HTTPMethod:#"POST"];
[newConnection addRequest:request completionHandler:handler];
[self.requestConnection cancel];
self.requestConnection = newConnection;
[newConnection start];
}
this is the good to upload image with some message .. if you want to upload a big image like Frontback

How do I choose which flexible sentence structure to post for my custom Open Graph story?

I have followed the tutorial about posting a custom Open Graph story using the Facebook SDK for iOS: https://developers.facebook.com/docs/ios/open-graph/
I have also read the docs about flexible sentence structures here: https://developers.facebook.com/docs/opengraph/creating-custom-stories/#variations
My question is, how and where do I specify in the code which specific sentence structure to use? I want to post "John Doe cooked a Steak" instead of "John Doe cooked a meal". I want to use the One-to-One sentence structure instead of the One-to-One Without Object Title structure.
// Create an object
id<FBGraphObject> object =
[FBGraphObject openGraphObjectForPostWithType:#"myapp:meal"
title:#"Steak"
image:#"http://i.imgur.com/g3Qc1HN.png"
url:#"https://example.com/link/"
description:#"Juicy and medium-rare"];
// Create an action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
// Link the object to the action
[action setObject:object forKey:#"meal"];
// Check if the Facebook app is installed and we can present the share dialog
FBOpenGraphActionShareDialogParams *params = [[FBOpenGraphActionShareDialogParams alloc] init];
params.action = action;
params.actionType = #"myapp:cook";
// 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:#"myapp:cook"
previewPropertyName:#"recipe"
handler:
^(FBAppCall *call, NSDictionary *results, NSError *error)
{
if(error) {
// There was an error
NSLog(#"Error publishing story: %#", error.description);
} else {
// Success
NSLog(#"result %#", results);
}
}];
}
I'm trying to figure that out also and here's why I understand so far:
By default, all posts are published on past tense. "Username ate a pizza"
If you want to use present tense, you have to set "end_time" attribute like this:
[action setEnd_time:#"2014-03-08T23:23:23"]; //a date on the future
This will look on user's timeline like "Username is eating a pizza" and that will continue showing like that until the date specified by end_time arrives.
I think that there could be an issue with time zones that I'm currently experiencing, so be careful if you need to handle different time zones.
According to documentation, "expires_in" attribute is a shortcut for "end_time" but instead of using a datime object, you can use a seconds delta, something like "this is in present tense until 500 seconds passed since it's been published", but I haven't been able to make this work (posts always shows as past tense)
[action setExpires_time:#"500"];
All other flexible sentences structures are managed by Facebook and you can't control when to show them. For instance, if two users of your app share content from it, it will show on friend's timeline something like "user1 and user2 are eating a pizza".
If you find out something else, please, update your post

"Could not generate preview text" error when creating object with Open Graph action

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?
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!");
}
}];
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.
I think i may know the reason that (#"url": #"http://test.com")->this may use the facebook app developer center offer.
click Open Graph
click Stories
then you will see your custom story on right side
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!
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.
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!");
}
}];
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

ios-Facebook SDK 3.0 Error 5 When Posting Status Update

I am trying out adding facebook integration in an app using the new (beta) facebook ios sdk 3.0. All I would like to is post a status update to facebook. I used a FBLoginView to login to facebook. I put my app id in the plist as instructed on facebook. I put in some code to post to facebook.
(void)viewDidLoad
{
[super viewDidLoad];
NSArray *perms;
perms = [NSArray arrayWithObjects:#"status_update", nil];
FBLoginView *loginview =
[[FBLoginView alloc] initWithPermissions:perms];
loginview.frame = CGRectOffset(loginview.frame, 5, 5);
loginview.delegate = self;
[self.view addSubview:loginview];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)poststatus:(UIButton *)sender {
NSString *message = [NSString stringWithFormat:#"Test staus update"];
[FBRequestConnection startForPostStatusUpdate:message
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
[self showAlert:message result:result error:error];
}];
}
- (void)showAlert:(NSString *)message
result:(id)result
error:(NSError *)error {
NSString *alertMsg;
NSString *alertTitle;
if (error) {
alertMsg = error.localizedDescription;
alertTitle = #"Error";
} else {
NSDictionary *resultDict = (NSDictionary *)result;
alertMsg = [NSString stringWithFormat:#"Successfully posted '%#'.\nPost ID: %#",
message, [resultDict valueForKey:#"id"]];
alertTitle = #"Success";
}
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:alertTitle
message:alertMsg
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
The odd thing is, this code works ONCE. After authenticating the user for the first time, I can post ONE status update successfully. After that, all subsequent attempts will fail with a FBiOSSDK error 5 (in the console, Error: HTTP status code:400). The only way to fix this is to remove the app from the facebook account and re-authenticate. I'm not sure what the problem is. I looked online for solutions but couldn't find anything. If anyone knows how to fix this, please let me know. Thanks
com.facebook.sdk error 5 is always irritating while working with Facebook iOS sdk. Most of the times it comes with addional in console Error: HTTP status code:400. Its a perception that there is a bug in Facebook iOS sdk that produces this error randomly. I think this error occurs for some certain reasons and sdk do not provide actual reason of error when it occurs.
Several Possible Reasons
Every request in sdk is accomplished with completion blocks that we actually pass as argument in completionHandler. This error occurs when a block is in progress and made another request. A simple example might be If you have written request to post on Facebook (startForPostStatusUpdate::) on some button action. On single button tap it would work fine but if you double tap on button it will throw this error com.facebook.sdk error 5
If you are trying to post when your current session is not opened. e.g. Once sign in with Facebook then kill the app then reopen and then try to share on Facebook, Result -> com.facebook.sdk error 5. In this case try to reopen session using
Facebook do not allow same status to be posted repeatedly, they think it might be some kind of spam e.g. If you are trying to update status and you have hard coded a string lets say #”This is a test status update” you are posing again and again. After 5 to 10 attempts they wont allow you to do anymore. Resulting com.facebook.sdk error 5. If this is the scenario you should change your status string and try updating.
Facebook has defined a limit for a particular user to post status using sdk. e.g If you are trying to update status and you have done lets say 15 to 20 status updates. They wont let you do more Resulting -> com.facebook.sdk error 5. In this scenario try to unauthorize the app from your Facebook account and reauthorize it OR try using other Facebook account
It seems there might be no answer to the issue. I have checked FB samples coming with SDK, in these examples also the same error happens. So it means after few status updates (15-20) Facebook reaches limits for that particular user. If you log-out for that user and log-in as another user, you can successfully post.
If I will find any extension to limit settings I will reply.
Also Facebook doesn't allow for the same Post.
Use a proxy !
FB ios SDK is just a wrap to an HTTP request to graph.facebook.com/....?access_token=.....
So you can easily replicate the request or use an HTTP proxy to see the real server answer (which is not error 5 !).

Resources