Finding the UserID of a Stack Overflow user with their Display Name in C#?
Asked Answered
B

3

5

I'm building a small Stack Overflow application, but to collect information from Stack Overflow about a user I need to know their UserID. I would like the user to be able to enter their display name/username and for the application to find their UserID. However, I understand that usernames are not unique, but would it be possible to find, through C#, all the user-ids of people with a username that I specify? Can you give me some sample code for this? This probably can be done somehow by screen-scraping the Users page, but I am not sure how to accomplish this sort of thing.

By the way, I do not want to use the data-dump to accomplish this. I would just like to somehow find this info out through the Users page, or something similar.

By the way, I posted a similar question on Meta Stack Overflow and was directed to post this here, as Stack Overflow is where it belongs!

Bondon answered 19/9, 2009 at 5:26 Comment(2)
I was about to suggest using the data dump, but you said you didn't want to use that for some unspecified reason. If you screen-scrape all the users on Stack Overflow, you will be banned.Wobbling
@Greg I will? Hmm... i don't want to screen-scrape all users, all I want to do is go through the Users page that says which users exist (the main Users page, not individual profile pages). This appears to be impossible.Bondon
M
7

The previous version of this answer doesn't work anymore. It could be modified to work again, but it's not necessary anymore – these days, there's the official API. The inname parameter to the /users method is what you're looking for.

Example: http://api.stackexchange.com/2.2/users?order=desc&sort=reputation&inname=steve&site=stackoverflow

Mechanical answered 19/9, 2009 at 11:20 Comment(3)
Thank you! This really helped! By the way, how'd you find this?Bondon
This doesn't work. Maybe this changed in the meantime?Clamworm
@Mitulátbáti Updated the answer.Mechanical
N
3

I hate to say it, but you might want to ask for the user ID.

The problem isn't that there are a lot of users with potential duplicates, because if that were the case you could just cache the lookups. The problem is that any user can change their display name at any time, and so you can't really trust your cache.

The one thing you might do is build a web service from the latest community wiki dump, keep that up to date, and just make users know that if they change their user name they'll need to wait for the next month's data release for the new name to work.

Noneffective answered 19/9, 2009 at 5:37 Comment(4)
Thank you! I'm just wondering, how do you change your user id? Is it related to associating a new OpenID with your account? I did that today, so I'm going to see if my id changed.Bondon
I'm guessing its randomly generated when your SO account is created in the database. changing openid wouldn't change it because one user can have multiple open ids. You would have to create a new user account to get a different IDIndented
@Indented ya that's what I think, except that it's not random, the IDs are ascending #s in terms of who registers first. Jeff has id #1. Other team members have single-digit ids. It's ordered by time! The ore people that register, the higher the id that is assigned to you will be!Bondon
That was a typo. It should have said "DisplayName"Noneffective
B
2

You will need to crawl through all users (https://stackoverflow.com/users/(0 to current)/) to answer that question.

Briscoe answered 19/9, 2009 at 5:29 Comment(1)
i was trying to find out if user ids are sequential, and this answer would imply that they are sequential.Importation

© 2022 - 2024 — McMap. All rights reserved.