gpt4 book ai didi

ios - Swift:尝试使用 Facebook Open Graph 故事

转载 作者:行者123 更新时间:2023-11-30 12:19:57 25 4
gpt4 key购买 nike

我正在尝试在 Swift 中使用 Facebook 的开放图谱故事功能,在用户每次查看某个位置时在时间轴上发布内容。但每次打开共享对话框时,我都会不断收到 this错误。

我按照 Facebook 文档创建了一个对象,然后是一个操作,最后是内容。但它似乎不起作用。

下面是我的代码:

class rateViewController: UIViewController, FBSDKSharingDelegate{

@IBOutlet weak var card: UIView!
@IBOutlet weak var cardBackground: UIView!

// VARIABLES

// CREATE THE OPENGRAPH OBJECT
var openGraphTest = FBSDKShareOpenGraphObject.init(properties: [

"place:location:latitude": "51.043553",
"place:location:longitude":"-114.078141",
"og:type" : "place",
"og:title" : "Rating"
])

// CREATE AN ACTION
var action = FBSDKShareOpenGraphAction.init()

// CREATE CONTENT
let content = FBSDKShareOpenGraphContent.init()

override func viewDidLoad() {
super.viewDidLoad()

action.actionType = "og.likes"
action.setObject(openGraphTest, forKey: "place")

content.action = action
content.previewPropertyName = "place"

// Do any additional setup after loading the view.
}

@IBAction func panCard(_ sender: UIPanGestureRecognizer) {

let card = sender.view! // Represents card UIView
let point = sender.translation(in: view) // How far you moved your finger, when touching view and dragging

card.center = CGPoint(x:(view.center.x + point.x), y: (view.center.y + point.y))

// RECENTERING THE CARD AFTER USER REMOVES FINGER FROM SCREEN

if(sender.state == UIGestureRecognizerState.ended){

if(card.center.x < 75){

// MOVE CARD TO THE LEFT SIDE OF SCREEN
UIView.animate(withDuration: 0.3, animations: {

card.center = CGPoint(x: self.cardBackground.center.x - 300, y: self.cardBackground.center.y + 75)
card.alpha = 0
})
return
}
else if(card.center.x > (view.frame.width - 75)){

// MOVE CARD TO THE RIGHT SIDE OF SCREEN
UIView.animate(withDuration: 0.3, animations: {

card.center = CGPoint(x: self.cardBackground.center.x + 300, y: self.cardBackground.center.y + 75)
card.alpha = 0
})
// SHOW THE FACEBOOK SHARE DIALOG

try FBSDKShareDialog.show(from: self, with: content, delegate: self)
return
}
UIView.animate(withDuration: 0.2) {
card.center = self.cardBackground.center
}
}
}

@IBAction func likeButton(_ sender: UIButton) {

// MOVE CARD TO THE RIGHT SIDE OF SCREEN

UIView.animate(withDuration: 0.3, animations: {

self.card.center = CGPoint(x: self.cardBackground.center.x + 300, y: self.cardBackground.center.y + 75)
self.card.alpha = 0
})

}

@IBAction func dislikeButton(_ sender: UIButton) {

// MOVE CARD TO LEFT SIDE OF SCREEN

UIView.animate(withDuration: 0.3, animations: {

self.card.center = CGPoint(x: self.cardBackground.center.x - 300, y: self.cardBackground.center.y + 75)
self.card.alpha = 0
})
}

// FACEBOOK SHARING DELEGATE

/**

Sent to the delegate when the share completes without error or cancellation.
- Parameter sharer: The FBSDKSharing that completed.
- Parameter results: The results from the sharer. This may be nil or empty.

*/
public func sharer(_ sharer: FBSDKSharing!, didCompleteWithResults results: [AnyHashable : Any]!){


}


/**

Sent to the delegate when the sharer encounters an error.
- Parameter sharer: The FBSDKSharing that completed.
- Parameter error: The error.

*/
public func sharer(_ sharer: FBSDKSharing!, didFailWithError error: Error!){

print("Error: ", error)
}


/**

Sent to the delegate when the sharer is cancelled.
- Parameter sharer: The FBSDKSharing that completed.

*/
public func sharerDidCancel(_ sharer: FBSDKSharing!){

self.dismiss(animated: true, completion: nil)
}
}

最佳答案

在联系 Facebook 并与他们的一位开发人员交谈后,起初我以为 API 中存在错误,但事实证明我做得不对。下面是我的代码:

// CREATE THE OPEN GRAPH OBJECT

let properties : [AnyHashable : Any] = [
"fb:ap_id":"APP ID FOUND ON FACEBOOK APP DASHBOARD",
"og:type":"object",
"og:title": "Some Title",
]

let object : FBSDKShareOpenGraphObject = FBSDKShareOpenGraphObject(properties: properties)

// CREATE AN ACTION

action.actionType = "og.likes"
action.setObject(object, forKey:"object")

// CREATE CONTENT MODEL

content.action = action
content.previewPropertyName = "object"

// SETTING UP THE SHARE DIALOG

shareDialog.fromViewController = self
shareDialog.shareContent = content

// SHOW THE SHARE DIALOG
if(shareDialog.canShow()){
shareDialog.show()
}
else{
print("Unable to show dialog")
}

do{
try shareDialog.validate()
}
catch{
print("Invalid")
}

关于ios - Swift:尝试使用 Facebook Open Graph 故事,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44915315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com