我想获取用户的个人资料图片。但是由于Facebook已经更新了其API SDK到v4.0或更高版本,而且在FB开发者网站上,他们正在用Objective C进行解释,但我需要Swift代码。我不知道如何在我的代码中使用FBSDKProfilePicture
。我需要帮助获取用户的个人资料图片。
我想将图片存储在我的第二个视图中。请任何人帮我编写代码。 这是我的代码。
class ViewController: UIViewController, FBSDKLoginButtonDelegate {
let loginManager = FBSDKLoginManager()
let loginView : FBSDKLoginButton = FBSDKLoginButton()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
if (FBSDKAccessToken.currentAccessToken() != nil)
{
println("user already logged in")
loginManager.logOut()
// User is already logged in, do work such as go to next view controller.
}
self.view.addSubview(loginView)
loginView.center = self.view.center
loginView.readPermissions = ["public_profile", "email", "user_friends"]
loginView.delegate = self
FBSDKProfile.enableUpdatesOnAccessTokenChange(true)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "onProfileUpdated:", name:FBSDKProfileDidChangeNotification, object: nil)
}
func returnUserData()
{
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in
if ((error) != nil)
{
// Process error
println("Error: \(error)")
}
else
{
println("fetched user: \(result)")
let userName : NSString = result.valueForKey("name") as! NSString
println("User Name is: \(userName)")
let userEmail : NSString = result.valueForKey("email") as! NSString
println("User Email is: \(userEmail)")
}
})
}
}
picture?width=10000
,因为它会返回比type=large
更大的尺寸。 - Sega-Zero