将webrequest解析为Coinbase,未授权401

时间:2014-08-02 22:52:39

标签: javascript parse-platform coinbase-api

我正在尝试通过Coinbase的API发送比特币,这是我的代码:

// create object to send as data
var transaction = {
    to : correctusermail, // "my@email.com"
    amount_string : amount, // "1.00"
    amount_currency_iso : currency // "EUR"
};

// get correct auth key from user
var authq = new Parse.Query(Parse.User);
authq.get(objectid, {
    success: function(userObject) {
    correctauth = userObject.get("provider_access_token");
    console.log(correctauth);


    console.log(transaction);
    // send post request
    // make post request
    Parse.Cloud.httpRequest({
      method: 'POST',
      url: 'https://coinbase.com/api/v1/transactions/send_money',
      headers: {
       'Content-Type': 'application/json;charset=utf-8'
      },
      body: {
        access_token: correctauth,
        transaction: transaction

     },
     success: function(httpResponse) {

        response.success(120);


     },
     error: function(httpResponse) {

    console.error('Request failed with response code ' + httpResponse.status);
                            response.error(111);
      }
    }); 
},
error: function(userObject, error) {

    response.error(150);
}
});

正如您所看到的,我通过记录确保我的correctauth var是正确的,这很好用。

所有其他变量都是正确的,我已经检查了它们。那我错过了什么?它可能非常小。

1 个答案:

答案 0 :(得分:0)

根据我对Coinbase API文档的理解,access_token应该始终是URL的一部分,例如

Parse.Cloud.httpRequest({
  method: 'POST',
  url: 'https://coinbase.com/api/v1/transactions/send_money?access_token=' 
    + correctauth,
  headers: {
   'Content-Type': 'application/json;charset=utf-8'
  },
  body: {
    transaction: transaction
  },
  // ... etc ...