Using C# to get user information
AnsweredHi,
I want to retrieve some user information, It is stated in the reference
" User Object: Italicized attributes are not returned by default and must be retrieved through the fields parameter."
For example, I want to check the information "IsPlatformAccessOnly", which is the Italicized attribute. How do I get this field information in C#, as this information is null from UsersManager.GetUserInformationAsync?
Thank you.
Joy
-
Hi,
I had this problem before and I ended up editing the SDK code itself.
Go to box-windows-sdk-v2\Box.V2\Managers folder and make changes to BoxUsersManager.cs file
public async Task GetCurrentUserInformationAsync(List fields = null)
{
BoxRequest request = new BoxRequest(_config.UserEndpointUri, "me")
.Param(ParamFields, fields);IBoxResponse response = await ToResponseAsync(request).ConfigureAwait(false);
return response.ResponseObject;
}and you can call this function as :
var bu = await SymBoxManager.Client.UsersManager.GetCurrentUserInformationAsync(new List() { "login", "space_used", "is_Platform_access_only" });
console.writeline(bu.is_platform_access_only)
Not exactly the way to do this but I didn't have any choice. You could probaly use inheritence and override the function yourself but i haven't tried it yet. let me know if you do that way.
Hope this helps.
thanks,
Bibek
-
Hi Bibek,
Based on your suggestion, I did the function overloading on the method
BoxUsersManager.GetUserInformationAsync. See the method definition below. It works well.
Thanks!
Joy
//
/// Retrieves information about a user in the enterprise. Requires enterprise administration authorization.
///
/// userId">The user identifier.
/// // fields">Attribute(s) to include in the response.
/// Returns the complete user object.
public async Task<BoxUser> GetUserInformationAsync(string userId, List<string> fields = null)
{
BoxRequest request = new BoxRequest(_config.UserEndpointUri, userId)
.Param(ParamFields, fields);
IBoxResponse<BoxUser> response = await ToResponseAsync<BoxUser>(request).ConfigureAwait(false);
return response.ResponseObject;
}
Please sign in to leave a comment.
Comments
2 comments