Updating/Adding/editing the Users Class when using Backendless/Facebook login...

Hi Backendless,
I am struggling with this one as I seem to be getting lots of FBSDK errors when trying to edit/update the data in the Users class for the currentUser.
I am using Objective-C and this is whats happening:
If i try to just simply update the Users class using the below:
-(void)updateProfile:(Users *)user
{
Responder *responder = [Responder responder:self
selResponseHandler:@selector(responseHandler:)
selErrorHandler:@selector(errorHandler:)];
user.telephone = telephone.text;
user.email = email.text;
id<IDataStore> dataStore = [backendless.persistenceService of:[Users class]];
[dataStore save:user responder:responder];
}
I get the error “Thread 1: EXC_BAD_ACCESS (code=EXC_1386_GPFLT” as the ‘user’ is nil… So! I call the save method first as suggested in the doc: https://backendless.com/documentation/data/ios/data_updating_data_objects.htm
-(void)saveProfile
{

Responder *responder = [Responder responder:self
selResponseHandler:@selector(responseHandler:)
selErrorHandler:@selector(errorHandler:)];
Users *user = [Users new];
user.name = nameCurrentUser;
user.email = email.text;
id<IDataStore> dataStore = [backendless.persistenceService of:[Users class]];
[dataStore save:user responder:responder];
}
However I get this error before the save method even completes: ‘Properties ‘password’ are required’ and nothing saves. The issue is I don’t have a password for the user as I use FB login plus I can’t make the Password a non-required field in the Schema for the User class… sigh
As an Parse customer I was used to calling the object and saving it back but here I don’t understand why the documents suggest I need to call the ‘save method’ before updating it. I just can’t get my head round it…
Please help…
Thanks
Steve

Hi Steve,

What is the “Users” class? You should be using the BackendlessUser class for any operation related to user objects.

Regards,
Mark

Ummm… I thought I was! The class name as far as the GUI is telling me is ‘Users’

None of our examples nor the doc mention that class anywhere. The class name must be BackendlessUser

hmmm… Does that mean then when looking at the Backendless GUI Class names could be something else other than displayed? maybe you should change that as even hovering over the class name to see if its truly Users still says that the class is called Users.

But it does explain a lot. I was following the documentation for ‘data update and deleting’ and substituted the class for the ‘Users’. As i say I just went to the GUI and looked to see what the Class name was and it clearly says Users… Maybe you should change that…

Also, can you confirm that if I need to update information in the BackEndlessUser class then I need to update the “Backendless.h” file with any new columns I have added?

Nearly there I think!

I am using this code from the docs for Updating User Properties and changed the user details to be currentUser and then set the field I wanted to update. All looks good doesn’t crash but I get the 'Password Required error again. I am using Backendless FB login SDK… Why is it falling over as there is no password? In the GUI it says its required but I can’t disable that nor can I delete the Password field from the schema.

-(void)updateUserPropsAsync {

BackendlessUser *user = backendless.userService.currentUser;

// user.email = @“james.bond@mi6.co.uk”;

// user.password = @“iAmWatchingU”;

[backendless.userService

registering:user

response:^(BackendlessUser *registeredUser) {

NSLog(@“User has been registered (ASYNC): %@”, registeredUser);

[registeredUser updateProperties:@{@“telephone” : @“10000”}];

[backendless.userService

update:user

response:^(BackendlessUser *updatedUser) {

NSLog(@“User has been updated (ASYNC): %@”, updatedUser);

[registeredUser updateProperties:@{@“telephone” : @“10000”}];

}

error:^(Fault *fault) {

NSLog(@“Server reported an error (ASYNC): %@”, fault);

}];

}

error:^(Fault *fault) {

NSLog(@“Server reported an error (ASYNC): %@”, fault);

}];

}

ERROR: Server reported an error (ASYNC): FAULT = ‘3041’ [Unable to register user. Missing required property value for ‘password’] <Unable to register user. Missing required property value for ‘password’>

Hi Steve,

If you need to add a custom property to your BackendlessUser objects - you should use the next BackendlessUser methods:

@interface BackendlessUser : NSObject
@property (nonatomic, assign, getter = getObjectId, setter = setObjectId:) NSString *objectId;
@property (nonatomic, assign, getter = getEmail, setter = setEmail:) NSString *email;
@property (nonatomic, assign, getter = getPassword, setter = setPassword:) NSString *password;
@property (nonatomic, assign, getter = getName, setter = setName:) NSString *name;
-(id)initWithProperties:(NSDictionary *)props;
-(NSString *)getUserToken;
-(void)setProperties:(NSDictionary *)props;
-(void)addProperties:(NSDictionary *)props;
-(NSDictionary *)getProperties;
-(void)updateProperties:(NSDictionary *)props;
-(id)getProperty:(NSString *)key;
-(void)setProperty:(NSString *)key object:(id)value;
-(void)removeProperty:(NSString *)key;
-(void)removeProperties:(NSArray *)keys;
@end

You can investigate our massive resources (with examples):
iOS API Doc - https://backendless.com/documentation/users/ios/users_update_user_properties.htm
Backendless API Cookbook - https://backendless.com/blog-a-feature-a-day-challenge/
and all sample from it in github: https://github.com/Backendless/BlogFeatureDay-iOS
Backendless iOS samples - https://github.com/Backendless/iOS-Samples

Regards,
Slava

thanks but can you share your thoughts on the error in the below comment please?

Yes, BackendlessUser class from API is mapped to Users table on the server. This underlines its special status.

The API doc doesn’t have enough in there regarding using the implementation and use of custom properties or at the least doesn’t describe the dependences or implementation of it.

A property ‘password’ is ‘Requied’ (see your screenshot), i.e. ‘password’ is indispensable, you may not to switch off it. And you MUST to set it before you register an user.

The Facebook login scenario (easy… or with FacebookSDK) do not require to set a password, because server gets it from Facebook. It is all right.

ok so why the error when trying to update?

In your code you got fault to ‘registering’ operation, not ‘update’.

And please clarify, if you already logged in with Facebook SDK and have ‘currentUser’ - why you again try to register him?

Because thats the code snippet from the Update User properties doc…

https://backendless.com/documentation/users/ios/users_update_user_properties.htm

I did think it was strange… But I don’t think its clear in the doc…

Oh, it is sample - anyone can quickly copypast and try it.
But only YOU have a SENCE about YOUR code!

In this case you should simply remove ‘registering’, your scenario doesn’t need it.

LMAO!!! Maybe I wasn’t meant to work with BackEndless but you have to smile!

Ok, so I seem one step closer but the ever creeping Password error has returned but in a different format!

Here is my code:

-(void)updateUserPropsSync {

BackendlessUser *user = backendless.userService.currentUser;



@try {

    

    [user updateProperties:@{@"email" : @"James@james.com"}];

    BackendlessUser *updatedUser = [backendless.userService update:user];

    NSLog(@"User has been updated (SYNC): %@", updatedUser);

}

@catch (Fault *fault) {

    NSLog(@"FAULT: %@", fault);

}

}

This is the error:

FAULT = ‘3072’ [Social user cannot use password.] <Social user cannot use password.>

It seems like it changes the data locally on the device but as you can see in the screen shot it doesn’t change the DB.

locally it shows the update:

2016-02-12 17:42:58.053 Panda[943:35122] user is logged in: <BackendlessUser> {

"Panda_Pounds" = 100;

"___class" = Users;

"__meta" = "{\"relationRemovalIds\":{},\"selectedProperties\":[\"Panda_Pounds\",\"password\",\"address\",\"created\",\"name\",\"___class\",\"telephone\",\"ownerId\",\"updated\",\"email\",\"objectId\",\"__meta\"],\"relatedObjects\":{}}";

address = "&lt;null&gt;";

created = "2016-02-07 14:35:20 +0000";

email = "James@james.com";

lastLogin = "2016-02-10 20:20:22 +0000";

name = name;

objectId = "36D47D86-94C6-D1B2-FF54-9299D6E60D00";

ownerId = "&lt;null&gt;";

password = "";

telephone = James;

updated = "2016-02-10 20:56:49 +0000";

"user-token" = "C3F20FC0-B868-021B-FF5E-7CCE308BA400";

}

Screen Shot 2016-02-12 at 17.41.22.png