2015-11-27 14:28:31 +08:00
|
|
|
var SteamCommunity = require('../index.js');
|
|
|
|
|
2015-12-03 10:35:35 +08:00
|
|
|
SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
|
|
|
|
var self = this;
|
2016-03-05 07:26:47 +08:00
|
|
|
this.httpRequest({
|
2016-09-02 03:05:46 +08:00
|
|
|
"uri": "https://steamcommunity.com/dev/apikey?l=english",
|
2015-12-03 10:35:35 +08:00
|
|
|
"followRedirect": false
|
|
|
|
}, function(err, response, body) {
|
2016-03-05 12:59:49 +08:00
|
|
|
if (err) {
|
|
|
|
callback(err);
|
2015-12-03 10:35:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(body.match(/<h2>Access Denied<\/h2>/)) {
|
|
|
|
return callback(new Error("Access Denied"));
|
|
|
|
}
|
2019-02-14 06:35:39 +08:00
|
|
|
|
2018-01-22 10:48:45 +08:00
|
|
|
if(body.match(/You must have a validated email address to create a Steam Web API key./)) {
|
|
|
|
return callback(new Error("You must have a validated email address to create a Steam Web API key."));
|
|
|
|
}
|
2015-12-03 10:35:35 +08:00
|
|
|
|
|
|
|
var match = body.match(/<p>Key: ([0-9A-F]+)<\/p>/);
|
|
|
|
if(match) {
|
|
|
|
// We already have an API key registered
|
|
|
|
callback(null, match[1]);
|
|
|
|
} else {
|
|
|
|
// We need to register a new API key
|
2016-09-02 03:05:46 +08:00
|
|
|
self.httpRequestPost('https://steamcommunity.com/dev/registerkey?l=english', {
|
2015-12-03 10:35:35 +08:00
|
|
|
"form": {
|
|
|
|
"domain": domain,
|
|
|
|
"agreeToTerms": "agreed",
|
|
|
|
"sessionid": self.getSessionID(),
|
|
|
|
"Submit": "Register"
|
|
|
|
}
|
|
|
|
}, function(err, response, body) {
|
2016-03-05 12:59:49 +08:00
|
|
|
if (err) {
|
|
|
|
callback(err);
|
2015-12-03 10:35:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.getWebApiKey(domain, callback);
|
2016-03-05 08:35:04 +08:00
|
|
|
}, "steamcommunity");
|
2015-12-03 10:35:35 +08:00
|
|
|
}
|
2016-03-05 08:35:04 +08:00
|
|
|
}, "steamcommunity");
|
2015-12-03 10:35:35 +08:00
|
|
|
};
|
|
|
|
|
2019-02-14 06:35:39 +08:00
|
|
|
/**
|
|
|
|
* @deprecated No longer works if not logged in via mobile login. Will be removed in a future release.
|
|
|
|
* @param {function} callback
|
|
|
|
*/
|
2015-11-27 14:28:31 +08:00
|
|
|
SteamCommunity.prototype.getWebApiOauthToken = function(callback) {
|
2020-11-05 15:42:31 +08:00
|
|
|
if (this.oAuthToken) {
|
|
|
|
return callback(null, this.oAuthToken);
|
2015-12-01 09:39:55 +08:00
|
|
|
}
|
|
|
|
|
2020-11-05 15:42:31 +08:00
|
|
|
callback(new Error('This operation requires an OAuth token, which can only be obtained from node-steamcommunity\'s `login` method.'));
|
2015-11-27 14:28:31 +08:00
|
|
|
};
|