使用未解析的标识符“ GraphRequestHTTPMethod”

时间:2019-04-08 11:01:03

标签: ios swift facebook-graph-api

我正在尝试在集成FBSDK之后获取用户详细信息。但是不幸的是,我收到诸如“使用未解析的标识符'GraphRequestHTTPMethod'”之类的错误。如果有人帮助我,那就太好了。谢谢!

func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
    let loginManager = FBSDKLoginManager()
    loginManager.logOut()
}
func getUserInfoFromFB() {

    let params = ["fields":"cover,picture.type(large),id,name,first_name,last_name,gender,birthday,email,location,hometown"]

    let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: params)
    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) // Respose is here.
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您需要使用 GraphRequest ,而不是 FBSDKGraphRequest ,这是工作代码(快速键4)

import FacebookCore
import FacebookLogin

func getUserInfoFromFB() {

    let params = ["fields":"cover,picture.type(large),id,name,first_name,last_name,gender,birthday,email,location,hometown"]
    let graphRequest = GraphRequest(graphPath: "me", parameters: params)
    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) // Respose is here.
            }
        }
    }
}

输出:

  

[“电子邮件”:abc@gmail.com,“ id”:1118625048361749,“名称”:   Nikunj Kumbhani,“图片”:{       数据= {           高度= 200;           “ is_silhouette” = 0;           url =“ https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=1118695008301542&height=200&width=200&ext=1557315519&hash=AeRP_G5QJ0Tlff-8”;           宽度= 200;       }; },“ last_name”:Kumbhani,“ first_name”:Nikunj]