ios - 使用 swift 5 的 facebook 图形请求
问题描述
我正在尝试按照他们的开发人员文档页面(https://developers.facebook.com/docs/swift/graph)上的描述实现一个 facebook 图形请求。Xcode 10.2.1,斯威夫特 5。
但我不断收到以下错误:
上下文闭包类型 '(GraphRequestConnection?, Any?, Error?) -> Void' 需要 3 个参数,但在闭包体中使用了 2 个
我做了很多研究并试图填写几个论点,但我根本无法弄清楚缺少的第三个论点可能是什么。
import FBSDKCoreKit
let connection = GraphRequestConnection()
connection.add(GraphRequest(graphPath: "/me")) { httpResponse, result in
switch result {
case .success(let response):
print ("Graph Request succeeded: \(resonse)")
case .failed (let error):
print ("Graph Request failed: \(error)")
}
}
connection.start()
有人可以帮忙吗?
解决方案
我有同样的行为。我在 Swift 和 Facebook Graph API 方面经验不足,我不确定这是否是一个好的解决方案,但目前(直到我找到更好的解决方案)对我来说是有效的:
connection.add(GraphRequest(graphPath: "/me", parameters: ["fields":"email"])) { httpResponse, result, error in
if error != nil {
NSLog(error.debugDescription)
return
}
// Handle vars
if let result = result as? [String:String],
let email: String = result["email"],
let fbId: String = result["id"] {
// internal usage of the email
self.userService.loginWithFacebookMail(facebookMail: email)
}
}
推荐阅读
- php - PHP练习函数($result)不能调用
- laravel - Laravel 8 Vue 包找不到声明模块
- angular - Angular 和基于 Spring 的 Web 应用程序中的验证码实现
- react-native - React Native 中的 PayPal 集成和支付状态
- java - 如何在 Appium 的页面工厂格式中转换 findElementByAndroidUIAutomator
- laravel - 从 $request 获取请求的中间件列表?
- java - java 被覆盖的方法不会抛出 java.lang.CloneNotSupportedException
- javascript - Playwright & NodeJs - 读取 CSV 并将数据推送到数组
- ios - 将 pngData() 崩溃为(NSCopying 和 NSObjectProtocol)?
- python - 带有 python 和 tkinter 问题的计算器