解析webrequest给Coinbase的401未授权

Parse webrequest to Coinbase gives 401 not authorized

本文关键字:授权 Coinbase webrequest 解析      更新时间:2023-09-26

我正在尝试通过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是正确的,它工作得很好。

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

根据我对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 ...