question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to get username from user

See original GitHub issue

Hello everyone,

I was unable to get the users usernames with your api. I am using the function GetAll(True, True) to get all users. But the username is not set in the returned User objects. In the documentation https://developer.wordpress.org/rest-api/reference/users/#arguments there is a context argument, which can be either view, embed or edit. I noticed, that most of the users attributes are available in the edit context. But you can only specify to use the embed context or not with your api. Is that the reason why I am no receiving the usernames of the users?

Thank you very much for your help!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
polushinmkcommented, Sep 3, 2018

@MarvinKlar if you want to perform the request with special context (not view), you should use QueryBuilder. For your purpose the following code might be helpful:

var userQuery = new UsersQueryBuilder {
     Context=Context.Edit,
//another conditions
};
var usersWithUsername = client.Users.Query(userQuery, true);

so this code should return users with username property

0reactions
chrisgatecommented, Sep 3, 2018
    /// <summary>
    /// Get current User
    /// </summary>
    /// <returns>Current User</returns>
    public Task<User> GetCurrentUser()
    {
        return _httpHelper.GetRequest<User>($"{_defaultPath}{_methodPath}/me", true, true);
    }

I think this is what /me can give you.

so my question @ThomasPe is there no other ways to get current user?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to retrieve the user identity (userName and ...
I am trying to implement this code to process the user login but does not work. It skips the if statement in the...
Read more >
aws cli - Unable to get userName because I did not specify ...
1 Answer 1 ... It should be possible to query for a user name with the user-name parameter. ... Retrieves details of the...
Read more >
Unable to find my username in C:\Users
6. Go back to the C:\Users folder and see if you find your account name. 8. Uncheck the checkbox Hidden, click Apply.
Read more >
Unable to get user email id after authentication
I tried adding “email” scope in the auth-service.js file & tried to retrieve this email id same way username & prof…
Read more >
"This doesn't look like a valid user ID" error when ...
Make sure you typed the user ID assigned to you by your organization. It usually looks like someone@example.com or someone@example.onmicrosoft.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found