使用OpenGraph FacebookSDK 4.4在Swift中发送图像和文本

时间:2015-08-04 15:03:40

标签: facebook swift facebook-graph-api xcode6 facebook-sdk-4.0

我在Swift App中使用Facebook SDK 4.4.0。 由于Facebook强制删除预填充文本,我试图使用Open Graph在我的应用程序上发布Facebook内容和图像。

我需要做的是向Facebook时间线发送一些文本内容和本地图像(不在网络上)。该图像是本地的,因此它在应用程序内。

我到目前为止所发现的是发送本地图像或内容,但我想将这两种内容一起发送。

以下是发送有效图像的Swift代码:

    @IBAction func facebookButton(sender: UIButton) {
        let photo : FBSDKSharePhoto = FBSDKSharePhoto()
        photo.image = UIImage(named: oldImageSaved! as String)
        photo.userGenerated = false

        var content : FBSDKSharePhotoContent = FBSDKSharePhotoContent()
        content.photos = [photo]

        let button:FBSDKShareButton = FBSDKShareButton()
        button.frame = CGRectMake(0, 0, 0, 0)
        button.shareContent = content
        button.sendActionsForControlEvents(UIControlEvents.TouchUpInside)
    }

这是OpenGraph代码,用于发送内容:

    @IBAction func facebookButton(sender: UIButton) {

            var current = NSUserDefaults.standardUserDefaults().objectForKey("currentPhrase") as? String
            var currentDescription = current!
            let ImageSaved = NSUserDefaults.standardUserDefaults().objectForKey("currentImageSaved") as? NSString

            // Create a FBSDKSharePhoto
            var photo : FBSDKSharePhoto = FBSDKSharePhoto()
            photo.image = UIImage(named: ImageSaved! as String)
            photo.userGenerated = false;

            let graphProperties : [NSObject : AnyObject]! = ["og:type": "fbtestapp:testing_test_app", "og:title":"Test App", "og:description": currentDescription]
            var graphObject : FBSDKShareOpenGraphObject = FBSDKShareOpenGraphObject(properties: graphProperties)

            // Create an action
            var action : FBSDKShareOpenGraphAction = FBSDKShareOpenGraphAction()

            action.actionType = "fbtestapp:merging"
            action.setObject(graphObject, forKey: "testing_test_app")

            // Create the content
            var content : FBSDKShareOpenGraphContent = FBSDKShareOpenGraphContent()
            content.action = action;
            content.previewPropertyName = "testing_test_app";

            FBSDKShareDialog.showFromViewController(self, withContent: content, delegate: nil)
    }

有关如何使用Swift中的OpenGraph发送包含一些文本内容的本地图像的任何帮助将非常感谢!

1 个答案:

答案 0 :(得分:2)

您需要批准您打开图表操作以获得其他功能:class CreateTestTable extends Migration { public function up() { Schema::create('test', function (Blueprint $table) { $table->string('id'); $table->timestamps(); $table->primary('id'); }); } public function down() { Schema::drop('test'); } } 。您可以在Open Graph Docs

中详细了解相关内容

需要审核此功能。获得批准后,您可以使用tinker对象上的User Messages参数。

请注意:仅当邮件直接来自用户时才允许这样做。如果您的应用程序预先填写此值,则会被阻止,您将无法使用它。