Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client.get_user().rich_presence not returning publicly available information #350

Open
mrKallah opened this issue Aug 13, 2021 · 5 comments
Labels

Comments

@mrKallah
Copy link

Using

from steam.client import SteamClient
from valve.steam.id import SteamID

client = SteamClient()

client.anonymous_login()

user_id = <<Any Steam ID>>

url = "https://steamcommunity.com/profiles/{}".format(user_id)

steam_id = SteamID.from_community_url(url)

a = client.get_user(steam_id, True)

print("Is logged on = ", client.EVENT_LOGGED_ON)
print("Username = ", a.name)
print("Steam ID= ", a.steam_id)
print("Friendship Status = ", a.relationship )
print("Rich Presence = ", a.rich_presence)

returns

Is logged on =  logged_on
Username =  None
Steam ID=  <<Input Steam ID>>
Friendship Status =  EFriendRelationship.NONE
Rich Presence =  {}

I have tried using cli_login() instead of anonymous_login().
I have tried using the user_id instead of the steam_id when calling client.get_user()
I have tried using both True and False when calling client.get_user() on the second argument
And I have tried mulitple steam community IDs.

It always returns empty usernames and rich presense.

@rossengeorgiev
Copy link
Contributor

Anonymous login is very limited. You cannot get persona state with it, you have to login as normal user. If the account is not part of your friendlist, you get limited information. I'm not sure if privacy settings of the user determine whether you get name or not. I think you get the name always, but only get reach presence and state for friends. The name is not username, its the display name. Username, as in the one you use to login, is never display anywhere for anyone except the user themselves.

@mrKallah
Copy link
Author

So, I did a bit more testing today, I tested mostly with my friends account until I went over to the anon acc. I then used my own account and was unable to get any info still. It seems that rich_presence returns empty dict regardless when not looking your own account up. This is seemingly regardless of privacy settings, as when I use the web version with my friends account it gives me the data I am looking for. I am assuming that any information that is open to the public on the web version should be available to the API?

I'll change the title to reflect this

@mrKallah mrKallah changed the title client.get_user() with valid ID returns empty username client.get_user().rich_presence not returning publicly available information Aug 16, 2021
@rossengeorgiev
Copy link
Contributor

rossengeorgiev commented Aug 21, 2021

I suggest enabling debug logging and looking at the contents of the persona state updates. See https://steam.readthedocs.io/en/latest/user_guide.html#logging

@mrKallah
Copy link
Author

I think the main problem here is that when looking at the page through a browser you get a slightly different version of the page than what the steam API does. When I look at the sources for the page from chrome (using incognito and not logged in) for a profile using a link:
https://steamcommunity.com/profiles/{ID}
And compare it with the source of the same profile using the Steam API (both logged in and not, and the profile I am looking for is not my friend on steam), I am unable to find the key parts of the sources using:

session = client.get_web_session()
site = session.get(url)
print(site.text)

From this, where the user has enabled the option to share this information, I am expecting to find a div with the class miniprofile_hover which is found using a web browser. This tag contains the key information that I am looking for - the rich presence data. I am, however, unable to find that same div in the sources that is downloaded using the python library. If the information is available to the public using a browser, then why is the same information not possible to extract using the API?

Here is the full code I am using without the steam IDs

from steam.client import SteamClient
from valve.steam.id import SteamID
import logging

client = SteamClient()
client.verbose_debug = True

# client.anonymous_login()
client.cli_login()

user_id = <<Any Steam ID of non-friend playing a game with game details privacy setting set to public here>>
# an easy way to ensure that the game sharing is enabled for a user, is to visit their page on the browser version in 
# incognito mode  hover over their profile picture and if a box shows up containing information about the game the 
# user is playing then you have the settings correct

url = "https://steamcommunity.com/profiles/{}".format(user_id)

steam_id = SteamID.from_community_url(url)

a = client.get_user(steam_id, False)

session = client.get_web_session()
site = session.get(url)
print(site.text)

@thunfischtoast
Copy link

thunfischtoast commented Nov 14, 2021

@mrKallah I tried the same use case and also ran into the problem. It becomes apparent why when look at what your browser does on connection level when loading the https://steamcommunity.com/profiles/{id}/games/?tab=all page: The raw HTML result is what you see downloaded as the result of the session.get(url)-call.

The raw HTML contains references to some external javascript dependencies and it also has some internal scripts which I presume build the actual game list after the initial page load.

There is one script with a variable called rgGames that is a list which contains the actual game info we want - however initially it is empty.

I see that this field is called twice in a script file called profile_gameslist_functions, but there the track is lost - I have no idea where or how this array is filled. Must be higher magic.

So, if there is no other way to obtain the friend's game list we'd have to do a full emulation (with javascript) of the browser...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants