【问题标题】:Share title, image and description using FBSDK for IOS使用 FBSDK for IOS 分享标题、图片和描述
【发布时间】:2016-07-03 01:43:12
【问题描述】:

我刚开始使用 iOS 版 Facebook idk,并希望允许用户从我的应用中分享图片、标题和描述,如下所示:

但我只得到标题和描述:s 这是我的代码:

let imageType: FBSDKSharePhoto = FBSDKSharePhoto(image: self.GenerateMapImage("\(latitude)",lng: "\(longitude)") , userGenerated: false)
            //let imageType2: FBSDKSharePhoto = FBSDKSharePhoto(image: UIImage(named: alertObj.id) , userGenerated: false)
            //
            imageType.caption = alertObj.alertType[0].name

            let content: FBSDKShareOpenGraphContent = FBSDKShareOpenGraphContent()
            let contentProp = ["og:type":"name_space:alert","og:title":"#\(name) \(addressName)","og:url" : "http://www.url.com"  , "og:description": description, "place:location:latitude":"\(latitude)", "place:location:longitude":"\(longitude)", "name_space:location:latitude":"\(latitude)", "name_space:location:longitude":"\(longitude)", "og:data:name_space:location:latitude":"\(latitude)", "og:data:name_space:location:longitude":"\(longitude)", "al:web:url" : "http://www.url.com"  ]

            let graphObj: FBSDKShareOpenGraphObject = FBSDKShareOpenGraphObject(properties: contentProp)
            graphObj.setArray([imageType], forKey: "og:image")

           // graphObj.setPhoto(imageType, forKey: "og:image")

            let facebookShare:FBSDKShareDialog = FBSDKShareDialog()
            let fbAction: FBSDKShareOpenGraphAction = FBSDKShareOpenGraphAction()
            facebookShare.delegate = alertActionsIntance
            fbAction.setArray([imageType], forKey: "og:image")
            fbAction.setObject(graphObj, forKey: "alert")
            fbAction.actionType = "name_space:share"

            content.action = fbAction
            content.previewPropertyName = "alert"

            facebookShare.mode = FBSDKShareDialogMode.Automatic
            facebookShare.shareContent = content;
            facebookShare.fromViewController = alertController;
            facebookShare.show()

这也是我的应用配置:

【问题讨论】:

    标签: ios facebook share facebook-opengraph fbsdk


    【解决方案1】:

    我在使用FBSDKSharePhoto 时遇到了类似的问题。如果您可以使用图像 url,只需将其作为字符串条目放入您的 contentProp 字典中,例如 "og:image":IMAGE_URL,它将显示为缩略图。

    这对我有用

    NSDictionary *properties  = @{
                                     @"og:type": @"",
                                     @"og:title":@"",
                                     @"og:description": @"",
                                     @"og:url":@"",
                                     @"og:image":@""
                                };
    
    
    }
    //Create an object
    FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
    // Create an action
    FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
    action.actionType = @"";
    [action setObject:object forKey:@""];
    
    // Create the content
    FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
    content.action = action;
    content.previewPropertyName = @"";
    
    [FBSDKShareDialog showFromViewController:self
                                 withContent:content
                                    delegate:self];
    

    【讨论】:

    • 嗨,我已经测试了将图像添加为字符串但仍然无法正常工作,我已将其添加到操作中:fbAction.setString(imageUrl, forKey: "og:image")
    • 我在上面编辑了我的答案,以反映对我有用的东西。希望对你有帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-13
    • 2012-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多