I was explicitly setting an "end_time" as the current date (vestigial code!). Removing the line allows this to work as it should.
Object Disappears in Open Graph Share Dialogue for iOS
-
10-06-2023 - |
题
I am trying to share a custom story via an open graph share dialogue for users not logged in via Facebook. My code is for the most part, taken directly from Facebooks examples with a few changes since we don't have any images. This seems to work initially. The app switches to Facebook with a correctly formatted preview. However, then the preview disappears and the "Post" button is grayed out. The user has no option except to cancel and return back to our application. I have also double checked all properties and namespaces.
NSString *urlDeepLink = [NSString stringWithFormat:@"http://www.appname.com?dropSpot='%@'&user='%@'&name='%@'&lat=%f&long=%f&rad=%d",place.objectId, [User currentUser].objectId, geospot.name, geospot.location.latitude, geospot.location.longitude, geospot.radius];
NSMutableDictionary<FBGraphObject> *object = [FBGraphObject openGraphActionForPost];
object[@"type"] = @"appname:action";
object[@"title"] = geospot.name;
object[@"description"] = place.detail;
object[@"url"] = urlDeepLink;
NSString *lat = [[NSNumber numberWithDouble:geospot.location.latitude]stringValue];
NSString *lng = [[NSNumber numberWithDouble:geospot.location.longitude]stringValue];
object[@"data" ] = @{ @"location": @{ @"latitude": lat, @"longitude": lng }};
object[@"fbsdk:create_object"] = @YES;
// create an Open Graph action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:object forKey:@"action"];
// add expiration date for correct story tenses
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH:mm:ssZ"];
action[@"end_time"] = [dateFormatter stringFromDate:[NSDate date]];
// Check if the Facebook app is installed and we can present the share dialog
FBOpenGraphActionShareDialogParams *params = [[FBOpenGraphActionShareDialogParams alloc] init];
params.action = action;
params.actionType = @"appname:set";
// 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:@"appname:set"
previewPropertyName:@"action"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
// There was an error
NSLog([NSString stringWithFormat:@"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
// Put together the dialog parameters
UIAlertView *alertUnableToPost = [[UIAlertView alloc]initWithTitle:@"Coudn't Post" message:@"We were unable to post your status to Facebook. This could be because you don't have the Facebook app installed on your phone." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alertUnableToPost show];
NSLog(@"Coudn't present share dialogue");
}
解决方案
不隶属于 StackOverflow