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
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
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
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
();
}
}
});
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
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]
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