Request for api not working properly

时间:2015-11-12 11:05:39

标签: javascript node.js

I'm making a request but it doesn't seem to work. If I copy code into my browser it works good, but in my console it shows up this :

{
  "status" : "success",
  "data" : {
    "error_message" : "API access enabled, but unable to verify two-factor authentication code. If you need help with this, please contact support@bitskins.com."
  }
}

What am I doing wrong? It's based on two-factor authentication that as I said works good while printing the url itself and when i'm copying it into my browser.

var url = 'https://bitskins.com/api/v1/get_item_price/?api_key='+bitskins.apikey+'&code='+bitskins.code+'&names='+encodeURIComponent(items[i].market_hash_name)+'&delimiter=!END!';
                console.log(url);
                request(url, function (error, response, body) {
                    if (!error) {
                        console.log(body)
                    }
                });

In case you want, here is my api key module to generating it (api key deleted for security)

var TOTP = require('onceler').TOTP;

//Create a TOTP object with your secret
var totp = new TOTP('deleted');

// print out a code that's valid right now
// console.log(totp.now());

var code = totp.now();

module.exports = {
    code: code,
    apikey: 'deleted'
}

3 个答案:

答案 0 :(得分:0)

BitSkins,Inc。的创始人。您需要具备以下条件:

1)您的API密钥 2)您的安全访问秘密

启用安全访问时,您会看到密码。如果您没有这个,只需禁用/重新启用安全访问并注意密码。您生成的TOTP代码是使用该秘密。在每次API调用之前生成TOTP代码,你就可以了。

答案 1 :(得分:0)

我认为它应该有效。对我而言,它运作良好。

var API_KEY = ''; //It is very important
var SECRET_KEY = ''; //It is very important

var totp = new TOTP(SECRET_KEY);
var code = totp.now();

var options = {
  url: 'https://bitskins.com/api/v1/get_item_price',
  form: {
    'api_key': API_KEY,
    'names': 'Tec-9%20%7C%20Sandstorm%20(Minimal%20Wear)',
    'delimiter': '!END!',
    'code': code
  }
};

function callback(error, response, body) {
  if (!error) {
    var info = JSON.parse(body);
    console.log(info);
  }
}

request.post(options, callback);

答案 2 :(得分:0)

你用什么npm包来创建2FA代码?我在示例中使用“onceler”但我认为它创建了wrond代码。这是我的代码:

var API_KEY = ''; //correct key from settings page
var SECRET_KEY = ''; // correct key which I copied from form with QR code.
var totp = new TOTP("SECRET_KEY");
var code = totp.now();

此代码不等于我在移动设备中可以看到的代码,并且使用此代码我会收到错误消息,例如作者的问题。但是,如果我将程序代码中的代码从我的手机中放入 - 它运行正常。那么我应该用什么包来获得正确的代码?