对象在iOS的Open Graph Share Dialogue中消失

时间:2014-03-06 19:03:22

标签: ios facebook facebook-graph-api facebook-opengraph

我正在尝试通过开放式图表共享对话为未通过Facebook登录的用户分享自定义故事。我的代码大部分都是直接来自Facebook的示例,但由于我们没有任何图像,因此会进行一些更改。这似乎最初起作用。该应用程序使用正确格式的预览切换到Facebook。但是,预览消失,“发布”按钮显示为灰色。除了取消并返回我们的应用程序之外,用户别无选择。我还仔细检查了所有属性和命名空间。

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");
}

1 个答案:

答案 0 :(得分:2)

我明确地将“end_time”设置为当前日期(残留代码!)。删除该行允许它按预期工作。