alex7kom / node-steam-tradeoffers

Steam Trade Offers for Node.js **NO LONGER MAINTAINED**
MIT License
288 stars 98 forks source link

403 on getOffers #81

Closed JakeCooper closed 9 years ago

JakeCooper commented 9 years ago

So I am able to getOffers when I run my brothers account (Which has games, playtime, etc), but when I run my bots, I get this 403 error.

Seems to be related to these, but I've tried everything suggested:

https://github.com/Alex7Kom/node-steam-tradeoffers/issues/32 https://github.com/Alex7Kom/node-steam-tradeoffers/issues/48

Here's my code

function getData() {
          var setTimer = setTimeout(getData, 10000);
          if (Date.now() - start > 300000){
            steamOfferObj.cancelOffer({
              tradeOfferId: data["tradeofferid"]
            }, function(){
              clearTimeout(setTimer);
              eventEmitter.emit('requestOfferExpired');
              return;
            })

          }
          steamOfferObj.getOffer({
              "tradeOfferId": data["tradeofferid"] // The tradeoffer id
          }, function(error, body) {
              console.log(body);
              console.log(error);
              if (error == null) {
                //console.log(body);
                console.log(body.response.offer.trade_offer_state);
                  if (body.response.offer.trade_offer_state == 3) {
                      eventEmitter.emit('requestOfferAccepted');
                      clearTimeout(setTimer);
                      return "Offer Accepted" //on accept
                  } else if(body.response.offer.trade_offer_state == 7){
                      eventEmitter.emit('requestOfferExpired');
                      clearTimeout(setTimer);
                      return "Offer cancelled";
                  } else {

                  }
              }
          });
        }
andrewda commented 9 years ago

I was getting a 403 error a while ago. I found that this is occurs when you attempt to send a steam message or trade offer before being successfully logged in. Try having your program wait 5 seconds before getting offers and see if that works.

JakeCooper commented 9 years ago

Well thing is, I can send tradeOffers fine, I just can't pole the offer using the getOffer command, so I don't think its an issue of not being signed in.

andrewda commented 9 years ago

Yes that is strange. I'll try your code any see what happens for me. It could just be that the steam inventory servers are down or slow at he moment.

JakeCooper commented 9 years ago

But also weird, because my alt account works, but not the bots.

andrewda commented 9 years ago

I think I found your issue. When I used your code with a random string of numbers for the tradeOfferId, I too got an error 403. However, after using a tradeOfferId that I had just sent, I received the correct output.

My guess is that you are trying to use a tradeOfferId from your alt account with your bots. Your bots can only check their own trade offers, so try using a tradeOfferId that you're sure your bot has and see if that works.

JakeCooper commented 9 years ago

The trade offer ID is generated in the callback for the makeOffer call, so I don't think that's it.

  steamOfferObj.makeOffer({
        partnerSteamId : steamID,
        accessToken : userAccessToken,
        itemsFromMe: '{}',
        itemsFromThem: objectArray
      }, function(err, data) {
        console.log(err);
        console.log(data);
        var start = Date.now();

        function getData() {
          var setTimer = setTimeout(getData, 10000);
          if (Date.now() - start > 300000){
            steamOfferObj.cancelOffer({
              tradeOfferId: data["tradeofferid"]
            }, function(){
              clearTimeout(setTimer);
              eventEmitter.emit('requestOfferExpired');
              return;
            })

          }
          steamOfferObj.getOffer({
              "tradeOfferId": data["tradeofferid"] // The tradeoffer id
          }, function(error, body) {
              console.log(body);
              console.log(error);
              if (error == null) {
                //console.log(body);
                console.log(body.response.offer.trade_offer_state);
                  if (body.response.offer.trade_offer_state == 3) {
                      eventEmitter.emit('requestOfferAccepted');
                      clearTimeout(setTimer);
                      return "Offer Accepted" //on accept
                  } else if(body.response.offer.trade_offer_state == 7){
                      eventEmitter.emit('requestOfferExpired');
                      clearTimeout(setTimer);
                      return "Offer cancelled";
                  } else {

                  }
              }
          });
        }

        getData();

      })
andrewda commented 9 years ago

Try outputting that tradeOfferId to the console and make sure it looks reasonable. I'm almost sure the 403 has to do with some error with the tradeOfferId.

JakeCooper commented 9 years ago

The one from my alt: http://i.imgur.com/zDOYY7Q.png

The one from my bot: http://i.imgur.com/HCOV2Ys.png

Seems reasonable to me.

andrewda commented 9 years ago

This seems to work perfectly for me:

function getData() {
  setTimeout(function () {
    offers.makeOffer({
      partnerSteamId: "76561198092490523",
      itemsFromMe: [ // make sure you have the square brackets
        {
          "appid": 440,
          "contextid": 2,
          "amount": 1,
          "assetid": "3585401379"
        }
      ],
      itemsFromThem: {}
    }, function(err, data) {
      console.log(data);
      console.log(err);
      offers.getOffer({
        "tradeOfferId": data["tradeofferid"] // The tradeoffer id
      }, function(error, body) {
        console.log(body);
        console.log(error);
        if (error == null) {
          console.log(body.response.offer.trade_offer_state);
            if (body.response.offer.trade_offer_state == 3) {
                return "Offer Accepted"; //on accept
            } else if(body.response.offer.trade_offer_state == 7){
                return "Offer cancelled";
            } else {
              //do something
            }
        }
      });
    });
  }, 5000);
}

http://i.imgur.com/L3HH5rw.png

JakeCooper commented 9 years ago

What did you change there?

Doesn't seem to be working with my bot account, but that code does work on my alt.

andrewda commented 9 years ago

I didn't change much there. It seems, though, that the error is on the bot's side. Have you disabled email confirmation for the bot? Has it been logged in from your Node-Steam for at least 7 days?

JakeCooper commented 9 years ago

The trade requests seem to send off fine, I just can't poll the trades. It's incredibly odd. Bots have a scraper that activates when the email comes in and auto verifies the trade, and the trades seem to send out fine so its not that, or the 7 day thing.

Spent a couple hours last night trying to tweak it but came up dry.

andrewda commented 9 years ago

Very odd. Hopefully someone more knowledgeable can shed some light on this.

RE-Roger commented 9 years ago

I think i found the reason for 403 problem. it's related to the apikey. The getOffer or getOffers method do not get apikey for you. You need to call SteamTradeOffers.prototype.getAPIKey for youself before you call the getOffer. Anyway,this solves my 403 problem. the latest version do get apikey automatically, i should update my package.

alex7kom commented 9 years ago

@l419351633 There is no SteamTradeOffers.prototype.getAPIKey and never was, what version you are using? getAPIKey function is not exposed to users.

RE-Roger commented 9 years ago

@Alex7Kom When I was using 1.0.3 version, the 403 problem was fixed by the getAPIKey. And i thought the 403 problem should be related to the apikey issues. The apikey relates to the account,so different accounts show different results.