使用Parse服務時,我試圖讓用戶通過Facebook登錄到應用程序並使用Facebook信息填寫字段來跳過登錄字段。我使用Parse的Cloud Code來儘可能簡化客戶端代碼。但是,當嘗試使用雲代碼設置Parse.User
的用戶名和電子郵件地址字段時,我從Parse.Cloud
得到了一點回響。運行它在應用程序中時出現以下錯誤。使用Cloud Code和PFFVideosUtils覆蓋電子郵件/用戶名
[Error]: Can't modify username in the before save trigger (Code: 141, Version: 1.6.1)
和刪除用戶名功能時,我得到:
[Error]: Can't modify email in the before save trigger (Code: 141, Version: 1.6.1)
通過相同的代碼,我還設置firstName
和lastName
不使用相同的方法的任何錯誤。以下是使用的代碼。
[CLOUD CODE]
function pad(num, size){ return ('000000000' + num).substr(-size); }
Parse.Cloud.beforeSave(Parse.User, function (request, response) {
var token = request.object.get("authData").facebook.access_token
Parse.Cloud.httpRequest({
url: 'https://graph.facebook.com/v2.1/me?fields=first_name,last_name,email&access_token=' + token,
success: function(httpResponse) {
var responseData = httpResponse.data;
request.object.set("email", responseData.email) // <- Error Occurs Here
request.object.set("username", responseData.email.split("@")[0].concat(".", pad(Math.floor(Math.random()*10000),4))) // <- Error Occurs Here
request.object.set("firstName", responseData.first_name)
request.object.set("lastName", responseData.last_name)
response.success()
},
error: function(){
response.error("Something went wrong.")
}
})
})
[SWIFT CODE]在這裏,我遇到
@IBAction func loginWithFacebookButtonAction(sender: AnyObject){
loginWithFacebookButtonOutlet.setTitle("Logging In...", forState: UIControlState.Normal)
let permissions = ["public_profile", "user_friends", "email"]
PFFacebookUtils.logInWithPermissions(permissions, {
(user: PFUser!, error: NSError!) -> Void in
if user == nil {
println("Uh oh. The user cancelled the Facebook login.")
} else if user.isNew {
println("User signed up and logged in through Facebook!")
self.performSegueWithIdentifier("facebookToApp", sender: self)
} else {
println("User logged in through Facebook!")
self.performSegueWithIdentifier("facebookToApp", sender: self)
}
})
}
其他問題所引起,當用戶試圖使用.save()
代替response.success()
這不似乎是這種情況下的問題。
非常感謝。
我有同樣的問題,你把它解決了嗎? –
我已經放棄了這個問題,並且假定它是一種硬編碼的預防措施,Parse使用它來保證輸入的完整性。 – schrismartin
@ChrisMartin通過放棄問題,你是否意味着你只是沒有設法解決它?如果你解決了它,你是怎麼做到的? – fatuhoku