DoctorMcKay / node-steamcommunity

Interact with various interfaces on Steam Community from Node.js
https://dev.doctormckay.com/forum/8-node-steamcommunity/
MIT License
476 stars 128 forks source link

getSteamUser SteamID64 or SteamID not working #251

Closed UnbreakCode closed 4 years ago

UnbreakCode commented 4 years ago

TypeError: Cannot convert undefined or null to object at Function.keys () at Object.exports.isSteamID (C:\Users\Niclas\Desktop\GitHub\Test\node_modules\steamcommunity\components\helpers.js:4:20)e_modules\steamcommunity\components\helpers.js:4:20) node_modules\steamcommunity\classes\CSteamUser.js:7:40) at SteamCommunity.getSteamUser (C:\Users\Niclas\Desktop\GitHub\Test\06:15)node_modules\steamcommunity\classes\CSteamUser.js:7:40)

Only Custom SteamID Link is working.

DoctorMcKay commented 4 years ago

Please show your code.

UnbreakCode commented 4 years ago

My Friend is providing a screenshot soon

Roo7K1d commented 4 years ago

Because the code is too long for a screenshot I will make a codeblock with the code.

if (url.includes("https")) {
                        //Im fall von custom-url
                        if (url.includes("id")) {
                            //parsen
                                profile = url.replace("https://steamcommunity.com/id/", "")
                                //Falls am Ende noch / sein sollte
                            if (profile.includes("/")) {
                                var steam = profile.replace("/", "")
                                console.log(steam)
                            } else {
                                var steam = profile
                                console.log(steam)
                            }
                        } else {
                            //parsen
                            profile = url.replace("https://steamcommunity.com/profiles/", "")
                            //Falls am Ende noch / sein sollte
                            if (profile.includes("/")) {
                                var steam = profile.replace("/", "")
                                console.log(steam)
                            } else {
                                var steam = profile
                                console.log(steam)
                            }
                        }
                    //Im Falle von HTTP Link
                    } else if (url.includes("http")) {
                        //Im fall von custom-url
                        if (url.includes("id")) {
                            //parsen
                                profile = url.replace("http://steamcommunity.com/id/", "")
                                //Falls am Ende noch / sein sollte
                            if (profile.includes("/")) {
                                var steam = profile.replace("/", "")
                                console.log(steam)
                            } else {
                                var steam = profile
                                console.log(steam)
                            }
                        } else {
                            //parsen
                            profile = url.replace("http://steamcommunity.com/profiles/", "")
                            //Falls am Ende noch / sein sollte
                            if (profile.includes("/")) {
                                var steam = profile.replace("/", "")
                                console.log(steam)
                            } else {
                                var steam = profile
                                console.log(steam)
                            }
                        }
                    }

What I want to do is I want to get some information of the user.

community.getSteamUser(steam, function(err, callback) {
                    name = callback.name
                    onlineState = callback.onlineState
                    vacBanned = callback.vacBanned
                    tradeBanState = callback.tradeBanState
                    location = callback.location
                    realName = callback.realName
                })

When I provide a steam link with a custom url my code works perfectly fine, but when I try to provide a link without a custom url (steamid64 instead) it throws this error:

TypeError: Cannot read property 'name' of undefined
    at C:\Users\irgen\OneDrive\Documents\GitHub\CommendYee\CommendYee\index.js:237:22
    at C:\Users\irgen\OneDrive\Documents\GitHub\CommendYee\CommendYee\node_modules\steamcommunity\classes\CSteamUser.js:29:5
    at Parser.<anonymous> (C:\Users\irgen\OneDrive\Documents\GitHub\CommendYee\CommendYee\node_modules\xml2js\lib\parser.js:304:18)
    at Parser.emit (events.js:310:20)
    at SAXParser.onclosetag (C:\Users\irgen\OneDrive\Documents\GitHub\CommendYee\CommendYee\node_modules\xml2js\lib\parser.js:262:26)
    at emit (C:\Users\irgen\OneDrive\Documents\GitHub\CommendYee\CommendYee\node_modules\sax\lib\sax.js:624:35)
    at emitNode (C:\Users\irgen\OneDrive\Documents\GitHub\CommendYee\CommendYee\node_modules\sax\lib\sax.js:629:5)
    at closeTag (C:\Users\irgen\OneDrive\Documents\GitHub\CommendYee\CommendYee\node_modules\sax\lib\sax.js:889:7)
    at SAXParser.write (C:\Users\irgen\OneDrive\Documents\GitHub\CommendYee\CommendYee\node_modules\sax\lib\sax.js:1436:13)
    at Parser.exports.Parser.Parser.parseString (C:\Users\irgen\OneDrive\Documents\GitHub\CommendYee\CommendYee\node_modules\xml2js\lib\parser.js:323:31) uncaughtException

So I think the script isn't creating a CSteamUser correctly when providing a steamid64 link.

Thanks for your help in advance.

DoctorMcKay commented 4 years ago

You don't seem to be handling the error in your callback.

Roo7K1d commented 4 years ago

Does that matter for the funcionality of the Code? Why does the custom URL work although the error isn't handled but the steamid64 doesn't?

DoctorMcKay commented 4 years ago

I don't know. Handle the error to find out.

itsjfx commented 4 years ago

The error callback will be useful, however on reading the docs for the method: https://github.com/DoctorMcKay/node-steamcommunity/wiki/SteamCommunity#getsteamuserid-callback

id - Either a SteamID object or a user's URL (the part after /id/)

You will need to make a SteamID object (https://github.com/DoctorMcKay/node-steamcommunity/wiki#steamid) out of the Steam64 you get from the URL, and use that as the id parameter.

Roo7K1d commented 4 years ago

Thanks for the help. I'm pretty confident that @itsjfx solution will work. I will write you again once I tested it.

Roo7K1d commented 4 years ago

Thanks to @itsjfx I could fix this issue. I've read the documentation for steamcommunity but I couldn't find how to create a SteamID object. Maybe @DoctorMcKay could update the documentation so it's more obvious to find. Thanks again for the help and the awesome packages! :)