I'm working on a Kinvey project right now, and I'm having some Problems with reading the Username or special Attributes from a User instance. I first tried it the same way getting _User.ID
by calling _User.UserName
, but this didnt return anything(But ID did curiously). I also searched on Google, but there weren't any articles about it. Hope you can help, would be greatly appreciated!
For special attributes, use the .Attributes
array on the User
class.
Like this code:
Console.WriteLine ("custom attribute is: " + kinveyClient.User ().Attributes["myAttribute"]);
For username, try .UserName()
but it seems you must do an explicit retrieval of the User object before this field is populated
User retrieved;
try {
retrieved = await kinveyClient.User().RetrieveAsync();
} catch (Exception e) {
Console.WriteLine("{0} caught exception: ", e);
retrieved = null;
}
Console.WriteLine ("logged in as: " + retrieved.Username );
Console.WriteLine ("custom attribute is: " + retrieved.Attributes["myAttribute"]);
Documentation: http://devcenter.kinvey.com/xamarin/guides/users#UserClass
(answer applies to SDK version 1.6.11)