简体   繁体   中英

How to login through api from Google Script?

I'm now working on the api of Gatecoin and want to get my open order on Google Sheet. I'm trying this:

function GetOrder() {
  var method = "GET"
  var URL = "https://api.gatecoin.com/Trade/Orders"
  var contentType = "application/json"
  var d = new Date()
  var now = d.getTime()
  var msg = method + URL + contentType + now
  var publicKey = :Public_key
  var privateKey = :Private_key
  var hash = Utilities.computeHmacSha256Signature(msg, privateKey, Utilities.Charset.US_ASCII);
  var hashInBase64 = Utilities.base64Encode(hash);

  var options ={
    'contentType': 'application/json',
    'method': method,
    'API_PUBLIC_KEY': publicKey,
    'API_REQUEST_SIGNATURE': hashInBase64,
    'API_REQUEST_DATE': now
  };

  var rdata = UrlFetchApp.fetch("https://api.gatecoin.com/Trade/Orders", options)

}

But the response mentions I was not logged in. What am I doing wrong?

I believe your options should have headers defined in an object as such:

  var options ={
    “contentType”: “application/json”,
    “method”: method,
    “headers”: {
      “API_PUBLIC_KEY”: publicKey,
      “API_REQUEST_SIGNATURE”: hashInBase64,
      “API_REQUEST_DATE”: now
    }
  };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM