I would like to save a string into Users class in backendless but the documentation seems confusing .
Hi Khoo,
There is no such thing as “Users” class. You should use the BackendlessUser class. The class provides method to set a property, it is called just that: “setProperty”. Once you set a property, you can save the object with the save API.
Regards,
Mark
Currently i am using facebook login but i wanna set the a column that i created which is displayName as the name of the facebook user
Hi Khoo,
Here is a function implementing you scenario:
func setCustomProperty(var user: BackendlessUser) {
Types.tryblock({ () -> Void in
// - user update
user.setProperty("hobby", object: "skating")
user = self.backendless.userService.update(user)
NSLog("UPDATED USER: %@", user.objectId)
},
catchblock: { (exception) -> Void in
NSLog("FAULT: %@", exception as! Fault)
}
)
}
You can investigate a doc (see ‘Swift’ bookmarks):
- to set custom property:
https://backendless.com/documentation/users/ios/users_update_user_properties.htm - to get custom property:
https://backendless.com/documentation/users/ios/users_get_current_user.htm
Also you can investigate this sample projects from our public github:
Regards,
Slava
Please see this comment in another thread - http://support.backendless.com/t/updatingaddingediting-the-users-class-when-using-backendlessfacebook-login#comment-6992
Hope it will be helpful for you.
can the displayName in the column be map to the facebook name ?
func easyFacebookLogin() {
let backendless = Backendless.sharedInstance()
var fieldsMapping: [NSObject : AnyObject] = ["id": "facebookId", "name": "name", "birthday": "birthday", "first_name": "first_name", "last_name": "last_name", "gender": "gender", "email": "email" ]
backendless.userService.easyLoginWithFacebookFieldsMapping(fieldsMapping, permissions: ["public_profile", "user_friends", "email", "user_photos"],
response: {(result : AnyObject!) -> Void in
print("Succefully Login With Facebook")
print ("Result: \(result)")
},
error: { (fault : Fault!) -> () in
print("Failed Login With Facebook")
print("Server reported an error: \(fault)")
})
}
Yes,
var fieldsMapping: [NSObject : AnyObject] = ["id": "facebookId", "displayName": "name", "birthday": "birthday", "first_name": "first_name", "last_name": "last_name", "gender": "gender", "email": "email" ]
That why i am thinking but after i change it say could not apporve social account
Really, you got a server response ‘could not approve social account’, but what is ‘displayName’? Indeed Facebook account has this field? I know it has ‘fisrt_name’ field, and code
[backendless.userService
easyLoginWithFacebookFieldsMapping:@{@"email":@"email", @"first_name":@"name"}
permissions:@[@"email"]
response:^(id response) {
//response - NSNumber with bool Yes
NSLog(@"Login: (Facebook) result = %@", response);
} error:^(Fault *fault) {
NSLog(@"%@", fault.detail);
}];
works fine.
as you can see name:name from facebook login returns null
Yes, this bug already is fixed, new version will be released after weekend, we will let you know about.
kk thanks