【问题标题】:Facebook Share Graph Object not working if adding image如果添加图像,Facebook Share Graph 对象不起作用
【发布时间】:2016-05-20 19:02:39
【问题描述】:

我正在尝试在 facebook 上分享一个图形对象,但我在添加图像时遇到了一些问题。

这是我当前的代码:

    // Construct an FBSDKSharePhoto
UIImage* psImg = [UIImage imageNamed:@"fb_share_logo"];
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = psImg;
photo.userGenerated = NO;

NSDictionary *properties = @{@"og:type": @"my_obj",
                             @"og:title": @"Title",
                             @"og:description": @"Description",
                             @"og:web": @"http://www.mywebssite.com"
//                           @"og:image": @[photo]
                             };

//create GraphObject from properties
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];

//create action
FBSDKShareOpenGraphAction *action = [FBSDKShareOpenGraphAction actionWithType:@"my_action" object:object key:@"my_key"];

//create content
FBSDKShareOpenGraphContent *content = [FBSDKShareOpenGraphContent new];

//set content action
content.action = action;
content.previewPropertyName = @"my_prop_type";

FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc] init];
shareDialog.fromViewController = self;
shareDialog.shareContent = content;
if (![shareDialog canShow]) {
    // update the app UI accordingly
    NSLog(@"is showing");
}
NSError *error;
if (![shareDialog validateWithError:&error]) {
    // check the error for explanation of invalid content
    NSLog(@"error");
}

if([shareDialog canShow]){
    [shareDialog show];
}

如果我不添加它可以工作的图像并且对话框显示但我需要它。如果我添加图像,我会得到:

【问题讨论】:

    标签: ios objective-c facebook facebook-graph-api share


    【解决方案1】:

    您的代码中未设置 shareDialog 的模式参数。

    所以首先你需要如下设置(more details here):

        dialog.mode = FBSDKShareDialogModeNative; // to open native app
        if (![dialog canShow]) {
            // if there is no FB app installed on that device, use browser
            dialog.mode = FBSDKShareDialogModeFeedBrowser;
    }
    

    如果您仍然无法打开共享对话框,您应该检查您的 Info.plist 文件中的 LSApplicationQueriesSchemes 键,看看它是否设置如下 (developers.facebook):

        <key>LSApplicationQueriesSchemes</key>
        <array>
            <string>fbapi</string>
            <string>fbapi20130214</string>
            <string>fbapi20130410</string>
            <string>fbapi20130702</string>
            <string>fbapi20131010</string>
            <string>fbapi20131219</string>    
            <string>fbapi20140410</string>
            <string>fbapi20140116</string>
            <string>fbapi20150313</string>
            <string>fbapi20150629</string>
            <string>fbauth</string>
            <string>fbauth2</string>
            <string>fb-messenger-api20140430</string>
        </array>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-01
      相关资源
      最近更新 更多