你好,我尝试从Facebook SDK
获得用户id, email, picture.type(large),updated_time
,我的成功让所有的人,但我没有得到图片给我如何斯威夫特获得的Facebook用户ID,电子邮件,picture.type(大)3
错误无法调用非函数类型的值'任何?!'
我的清晰代码如下。
import UIKit
import Foundation
class LoginViewController : UIViewController, FBSDKLoginButtonDelegate {
private var fromLogin = [Login]()
@IBOutlet weak var loginButton : FBSDKLoginButton!
override func viewDidLoad() {
super.viewDidLoad()
// Check Session
if let token = FBSDKAccessToken.current(){
print(token.tokenString! as Any)
self.fetchProfile()
}
loginButton.delegate = self
loginButton.readPermissions = ["email", "public_profile"]
}
// Get Profile
func fetchProfile() {
print("fetch profile")
// Create facebook graph with fields
FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"id, name, email, picture.type(large), updated_time"]).start { (connection, result, error) in
// check error
if error != nil {
// error happen
print("Failed to start graph request: \(error?.localizedDescription)")
return
}
if let userDict = result as? NSDictionary {
let name = userDict["name"] as? String
let id = userDict["id"] as? String
let email = userDict["email"] as? String
// HERE GIVES ERROR I DIDNT GET PICTURE WITH STRING
let userPicture = userDict.objectForKey("picture")?.objectForKey("data")?.objectForKey("url") as String
print(userPicture)
print(name as Any)
print(id as Any)
print(email as Any)
}
}
}
// Delegate Method
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!){
// check error
if error != nil {
// error happen
print(error?.localizedDescription as Any)
return
}
print("Successfull login in with facebook...")
fetchProfile()
}
func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!){
print("Log Out")
}
该行给出错误;
让userPicture = userDict.objectForKey( “图片”)?objectForKey( “数据”)?objectForKey( “URL”)作为字符串
另外图片浏览对象JSON数据示例;
picture = {
data = {
"is_silhouette" = 0;
url = "https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/14067524_9513823423422249533237851_n.jpg?oh=88eb9b80abbb2342346c01de298&oe=58C5138B";
};
};
进出口使用Xcode 8.1
和Swift 3.0
谢谢!
试试下面的答案 – User511
@ User511我的代码工作只需要获得图片真实串码 – SwiftDeveloper
它有完整的代码。它为我工作。 – User511