我对IOS非常陌生,我刚刚开始使用Facebook的API-Graph。
现在我想要执行"/me“查询,但是我得到了以下错误:
未解析标识符“GraphRequest”的使用
这是我的密码:
import UIKit
import FBSDKCoreKit
import FBSDKLoginKit
....
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
if ((error) != nil)
{
// Process error
}
else if result.isCancelled {
// Handle cancellations
}
else {
if result.grantedPermissions.contains("public_profile") && result.grantedPermissions.contains("user_friends") && result.grantedPermissions.contains("user_posts") && result.grantedPermissions.contains("user_photos")
{
//HERE IS MY QUERY
let params = ["fields" : "email, name"]
let graphRequest = GraphRequest(graphPath: "me", parameters: params) <-- HERE I GOT THE ERROR
graphRequest.start {
(urlResponse, requestResult) in
switch requestResult {
case .failed(let error):
print("error in graph request:", error)
break
case .success(let graphResponse):
if let responseDictionary = graphResponse.dictionaryValue {
print(responseDictionary)
print(responseDictionary["name"])
print(responseDictionary["email"])
}
}
}
guard let presentedController = self.storyboard?.instantiateViewController(withIdentifier: "01") else { return }
presentedController.modalTransitionStyle = UIModalTransitionStyle.partialCurl
self.present(presentedController, animated: true, completion: nil)
}
}
guard let presentedController = self.storyboard?.instantiateViewController(withIdentifier: "01") else { return }
presentedController.modalTransitionStyle = UIModalTransitionStyle.partialCurl
self.present(presentedController, animated: true, completion: nil)*/
}else{
//cambia stato bottone
let alert = UIAlertController(title: "Missing Permission", message: "We need all the permission for continue", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
}我把进口和FB登录做得很好。我做错了什么?(我用Swift 3)
更新2:

发布于 2017-01-03 22:17:58
GraphRequest应该是FBSDKGraphRequest。
let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: params)注意:除了Swift SDK之外,还有一个Swift特定的。https://developers.facebook.com/docs/swift
编辑:
根据您更新的问题,FBSDKGraphRequest似乎可以返回一个可选选项。可选的意思是您将得到FBSDKGraphRequest或nil的一个实例。
您可以通过几种不同的方式处理可选选项。
guard构造if let构造?使用guard
guard let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: params) else {
// Handle the fact that graphRequest is nil
}
graphRequest.start { ... } // graphRequest is guaranteed to be not nil使用if let
if let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: params) {
graphRequest.start { ... } // graphRequest is guaranteed to be not
} else {
// Handle the fact that graphRequest is nil
}使用?
let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: params)
graphRequest?.start { ... }如果graphRequest是nil,这将不会有任何作用。
编辑2:
您似乎在使用Facebook方法来调用start方法,而不是使用iOS SDK方式。
FBSDKGraphRequestHandler是用以下参数定义的typedef:
FBSDKGraphRequestConnection连接id结果NSError错误因此,在调用start时,需要在闭包中考虑这些参数。
graphRequest.start { connection, result, error in
...
}或者对您不感兴趣的参数使用_。
graphRequest.start { _, result, _ in
...
}注意:您的switch语句很可能不适用于上面的代码。您需要进行进一步的更改,以使它能够使用所提供的参数(连接、结果和错误)。同样,您可能正在混合Facebook的Swift代码和iOS SDK代码。
https://stackoverflow.com/questions/41453204
复制相似问题