在后台将带有标题的照片分享到 Facebook
Posted
技术标签:
【中文标题】在后台将带有标题的照片分享到 Facebook【英文标题】:Sharing photo with caption into facebook in background 【发布时间】:2017-08-24 11:04:32 【问题描述】:我在后台使用以下代码成功地将图片发布到了 Facebook,但不知何故不知道如何包含标题。我已经阅读了官方文件,但仍然找不到任何文件。请帮忙。提前致谢。
import UIKit
import FBSDKLoginKit
import FBSDKShareKit
class ViewController: UIViewController, FBSDKLoginButtonDelegate, FBSDKSharingDelegate
override func viewDidLoad()
super.viewDidLoad()
let loginButton = FBSDKLoginButton()
loginButton.center = view.center
view.addSubview(loginButton)
loginButton.delegate = self
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!)
if (FBSDKAccessToken.current() != nil) FBSDKGraphRequest(graphpath: "me", parameters: nil).start(completionHandler:
(connection, result, error) in
if error == nil
print("fetch user \(result)")
)
func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!)
print("you logout")
@IBAction func postImage(_ sender: Any)
let img = UIImage(named: "image")
let content = FBSDKSharePhotoContent()
content.photos = [FBSDKSharePhoto(image: img, userGenerated: true)]
FBSDKShareAPI.share(with: content, delegate: self)
func sharerDidCancel(_ sharer: FBSDKSharing!)
print("sharerDidCancel")
func sharer(_ sharer: FBSDKSharing!, didFailWithError error: Error!)
print("didFail")
func sharer(_ sharer: FBSDKSharing!, didCompleteWithResults results: [AnyHashable : Any]!)
print("didCompleteWithResult")
【问题讨论】:
【参考方案1】:试试这个:-
@IBAction func postImage(_ sender: Any)
let img = UIImage(named: "image")
let photo = FBSDKSharePhoto()
photo.image = img
photo.caption = "Test Caption"
photo.isUserGenerated = true
let content = FBSDKSharePhotoContent()
content.photos = [photo]
FBSDKShareAPI.share(with: content, delegate: self)
【讨论】:
以上是关于在后台将带有标题的照片分享到 Facebook的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Objective-C 中将照片分享到 Facebook?
如何通过 iphone 应用程序将照片/图像上传到 facebook
在 Facebook 时间线上分享照片而不是个人资料图片:Android