This is a migrated thread and some comments may be shown as answers.

Updating users

9 Answers 37 Views
Android SDK
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mark
Top achievements
Rank 1
Mark asked on 31 Mar 2016, 01:40 PM

I am trying to update users who registered with faceebook to include their email addresses. i have tried the code in the documentation but i get an incompatible types error.

public void updateUserById(EverliveApp app, UUID userId, User updateObject) {
    User user = app.workWith().users().getById(userId);
    Log.i("App_name", "Username: " + user.getUsername());
    app.workWith().users().updateById(userId, updateObject).executeSync();
}

the error is on the line:       User myUser = app.workWith().users().getMe().executeSync();

 

User is of type:

com.telerik.everlive.sdk.core.model.system.user

And

app.workWith().users().getMe().executeSync() returns : 

com.telerik.everlive.sdk.core.facades.read.getByIdFacades

9 Answers, 1 is accepted

Sort by
0
Anton Dobrev
Telerik team
answered on 01 Apr 2016, 03:33 PM
Hello Mark,

You can obtain the Users in the same way as other data types (as shown here). For example:

RequestResult<User> myUser = app.workWith().users(User.class).getById(userId).executeSync();

We will update the documentation for reading users with the appropriate code snippet.

Let me know if this works for you.

Regards,
Anton Dobrev
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
Kevin
Top achievements
Rank 1
answered on 01 Apr 2016, 04:02 PM

but this does not return a User object and i cant access its attributes

like in the log in the original post "user.getUsername()" getUsername() is unresolved

0
Kevin
Top achievements
Rank 1
answered on 01 Apr 2016, 04:08 PM
disregard the last post
0
Mark
Top achievements
Rank 1
answered on 04 Apr 2016, 01:09 PM

i was also having a different problem with this it appears the user is not getting loggid in after loginwithfacebook is called. Why is this?

app.everliveApp.workWith().authentication().loginWithFacebook(facebookToken).executeAsync(new RequestResultCallbackAction() {
@Override
public void invoke(RequestResult requestResult) {
  Log.d("TAG","Login To Telerik With Facebook Called!");
  if (requestResult.getSuccess()) {
         Log.i("TAG -- ", loginResultFacebook.getId().toString()); // prints 00000000-0000-0000-0000-000000000000
  //getUsername(app.everliveApp,loginResultFacebook.getId());
    Intent i = new Intent(LoginActivity.this, MainActivity.class);
  startActivity(i);
  finish();
  }
  }
});
0
Anton Dobrev
Telerik team
answered on 05 Apr 2016, 01:35 PM
Hi Mark,

Usually, the login method will only return the access token of the logged in user as returned from the server. To get the user account properties for the current user utilize the getMe method. For example:

everliveApp.workWith().authentication().loginWithFacebook(facebookToken).executeAsync(new RequestResultCallbackAction() {
           @Override
           public void invoke(RequestResult requestResult) {
 
               if(requestResult.getSuccess()) {
                   // get the current user
                   everliveApp.workWith().users().getMe().executeAsync(
                           new RequestResultCallbackAction() {
                               @Override
                               public void invoke(RequestResult requestResult) {
 
                                   if (requestResult.getSuccess()) {
                                       // the user is logged in
                                      // access the user properties
                                     User myUser = (User) requestResult.getValue();
                                       myUser.getId();
 
                                   } else {
                                       // the user is not logged in
                                   }
                               }
                           }
                   );
               }
           }
       });

I hope that this works for you.

Regards,
Anton Dobrev
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
Kevin
Top achievements
Rank 1
answered on 05 Apr 2016, 01:55 PM
Do I need the call this every time i create data objects? as now when i create any data object is is created in the back end but the created/modified by fields are empty. Also are there any issues with the platform as any user or data created from an android device appears to be created (no errors) but cant be viewed @ platform.telerik.com. i can create users and login with the credentials but they don't appear on the site. on IOS i cant create a user. i get returned the provided access token is invalid or has expired , but this problem went away by uninstalling the app (just ios).
0
Mark
Top achievements
Rank 1
answered on 05 Apr 2016, 01:59 PM

Sorry @Anton Dobrev  as you may have gathered i am signed in to 2 platform accounts in different browsers.

 

[quote]Mark (Actually) said:Do I need the call this every time i create data objects? as now when i create any data object is is created in the back end but the created/modified by fields are empty. Also are there any issues with the platform as any user or data created from an android device appears to be created (no errors) but cant be viewed @ platform.telerik.com. i can create users and login with the credentials but they don't appear on the site. on IOS i cant create a user. i get returned the provided access token is invalid or has expired , but this problem went away by uninstalling the app (just ios).[/quote]

0
Anton Dobrev
Telerik team
answered on 07 Apr 2016, 08:43 AM
Hello Mark,

As to your questions.

Do I need the call this every time i create data objects? as now when i create any data object is is created in the back end but the created/modified by fields are empty.

It may be a good idea to check if a user is logged in (users.getMe())   prior to making any application critical operations with the server. This way you ensure that the user is logged in and the items created in the database will be set their system fields.

For more info on the system fields and how they are set see support thread 1023909.

For more info on managing the state of the current user see here.

Also are there any issues with the platform as any user or data created from an android device appears to be created (no errors) but cant be viewed @ platform.telerik.com. i can create users and login with the credentials but they don't appear on the site.

This sounds like a really peculiar behavior. To provide you with a resolution:

- Can you confirm that you are exploring the data in the portal for the same project as its App ID in the client app?

- Can you show some screenshots or provide an API key (App Id) to check on our side?

- What happens if you issue a GET request to the Users endpoint as explained here?

- Can you create a data item from the portal?

 on IOS i cant create a user. i get returned the provided access token is invalid or has expired , but this problem went away by uninstalling the app (just ios).

This error means that there is a logged in user in the app but the user access token expired or is no longer valid. Please refer to this forum thread for more info.

Let me know if this works for you.

Regards,
Anton Dobrev
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
Mark
Top achievements
Rank 1
answered on 07 Apr 2016, 08:51 AM
Thank you for your reply. All issues have been solved. On the peculiar behavior, my colleague changed the app id in the wrong project which meant it was working on the device but the data was going to the wrong app on the back end.
Tags
Android SDK
Asked by
Mark
Top achievements
Rank 1
Answers by
Anton Dobrev
Telerik team
Kevin
Top achievements
Rank 1
Mark
Top achievements
Rank 1
Share this question
or