2014-04-29 45 views
1

对于电子表格在谷歌驱动器建设,我想拉我的天平从交易网站。我有一个使用JSON GET方法的函数,但现在我需要找到一个适用于JSON POST数据的函数。该功能应使用3个参数,因此我可以在电子表格中选择这些参数:谷歌脚本 - JavaScript函数发送JSON POST请求

  1. url。
  2. 键(API密钥)
  3. 号(秘密)

这些都是与函数发送的头!

网站(poloniex.com/api)有一个请求以下要求:

All calls to the trading API are sent via HTTP POST to https://poloniex.com/tradingApi and must contain the following headers: 

Key - Your API key. 
Sign - The query's POST data signed by your key's "secret" according to the HMAC-SHA512 method. 
Additionally, all queries must include a "nonce" POST parameter. The nonce parameter is an integer which must always be greater than the previous nonce used. 

所以,任何人都可以给我提供.GS的工作版本或指向我一个很好的来源。 另外,我不知道如何编写随机数的代码。

+0

它到底如何工作? – brauliobo

回答

1

UrlFetchApp.fetch()的文档描述了您可以使用的可选参数。将参数method设置为“发布”以发送POST请求而不是GET。

您可以使用Utilities.computeHmacSignature()来签署请求,不过要弄清楚这可能会很棘手。

至于nonce,使用当前的时间戳可能就足够了,从new Date().getTime()可用。