ios - 如果添加图像,Facebook 共享图形对象不起作用

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

我正在尝试在 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];
}

如果我不添加图像,它会工作并且对话框会显示,但我需要它。如果我添加图像我得到这个: enter image description here

最佳答案

您的代码中未设置 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>

关于ios - 如果添加图像,Facebook 共享图形对象不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35315010/

相关文章:

objective-c - 查看首次安装的应用程序版本 - iOS

ios - 如何防止未初始化数据的快速 CoreData 崩溃

javascript - Microsoft.Owin.Security.Facebook 与 Facebook SDK for Javascript

ios - 如何 Hook 私有(private)框架

ios - 在 Viewcontroller 上创建自定义键盘

objective-c - 在 Cocoa Status Bar 应用程序中接收 keyDown 和 keyUp 事件

objective-c - NSDateFormatter 为 12/30/2012 和 12/31/2012 提前一年

ios - 在另一个 View Controller 中显示 View Controller 时如何防止闪烁

iphone - 使用FBRequestConnection错误处理程序获取Facebook数据时出现问题

java - 如何在 Netbeans 上添加 facebook 作为 Web 服务