• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

javascript - 使用 Cloud Code 和 PFFacebookUtils 覆盖电子邮件/用户名

[复制链接]
菜鸟教程小白 发表于 2022-12-12 13:25:44 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

在使用 Parse 服务时,我试图让用户跳过登录字段,方法是通过 Facebook 登录应用程序并使用 Facebook 信息填写字段。我正在使用 Parse 的 Cloud Code 来使 swift 客户端代码尽可能简单。但是,当我尝试使用云代码设置 Parse.User 的用户名和电子邮件地址字段时,我得到了来自 Parse.Cloud 的一些反馈。在应用内运行时出现以下错误。

[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)

通过相同的代码,我还使用相同的方法设置 firstNamelastName 没有任何错误。下面是使用的代码。

[云代码]

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 代码]

@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() 时引起的,这似乎没有是这种情况下的问题。

非常感谢。



Best Answer-推荐答案


似乎 username & email 不能在 beforeSave 触发器中更改,因为它们应该是唯一的

Right now, the email field cannot be modified on a beforeSave because this field should be unique. If you were to use a value that another user is already using, this would result in an error that your beforeSave method would not be able to handle.

引用:https://www.parse.com/questions/why-cant-i-modify-the-email-field-in-a-before-save-trigger

关于javascript - 使用 Cloud Code 和 PFFacebookUtils 覆盖电子邮件/用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27643307/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap