【问题标题】:Parse webrequest to Coinbase gives 401 not authorized解析对 Coinbase 的 webrequest 给出 401 未授权
【发布时间】:2014-08-02 22:52:38
【问题描述】:

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

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

【问题讨论】:

    标签: javascript parse-platform coinbase-api


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多