我正在尝试将我的应用中的现有帐户链接到facebook帐户,但是在解析API中成功的参数始终返回false(无错误)我能够使用API创建新用户,发布和读取用户信息等,但当我尝试使用下面的代码链接帐户时,它总是失败:
func facebook(user: PFUser){
let request = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"])
request.startWithCompletionHandler { (connection:FBSDKGraphRequestConnection!, result:AnyObject!, error:NSError!) -> Void in
if let error = error {
println("error requesting FBSDKGraphRequest \(error.localizedDescription)")
} else{
let userData = result as! NSDictionary
println(userData)
let facebookID = userData["id"] as! String
user.username = userData["name"] as? String
if let email = userData["email"] as? String{
//find user email on facebook
user.email = email
if let checkForUser = CreateConnection.findUserByEmail(email){
//find PFUser that have that email
println("find a match for old user on facebook")
if !PFFacebookUtils.isLinkedWithUser(checkForUser) {
//the PFUser that has the email is not already linked with facebook
PFFacebookUtils.linkUserInBackground(checkForUser, withReadPermissions: nil, block: {
//link account in the background
(succeeded: Bool, error: NSError?) -> Void in
//no error return
if let error = error{
println("error linking user to facebook \(error.localizedDescription) ")
}
//succeeded return false
if succeeded {
println("the user is now linked with Facebook!")
} else{
//this line is printed
println("link did not succeeded")
}
})
}
} else{
//code to create a new account here
}
这就是我在appDelegate中所拥有的:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
}
PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url,sourceApplication: sourceApplication, annotation: annotation)
}
我注意到的另一个奇怪的行为是facebook屏幕授权应用程序弹出两次,一旦你按照预期点击登录,一旦调试器点击块linkUserInBackground结束(甚至进去之前)还)
答案 0 :(得分:0)
只有经过身份验证的用户才能编辑自己的数据。用户无法编辑其他用户,甚至无法编辑ACL。 我认为唯一的解决方案是使用云功能和万能钥匙。 https://parse.com/docs/cloudcode/guide#cloud-code