【问题标题】:Required parameter missing: account缺少必需参数:帐户
【发布时间】:2015-01-31 22:35:54
【问题描述】:

我正在使用 Coinbase API,请visit here 了解有关此 API 的更多信息。

所以,我正在运行这个程序,你可以看一下,但它说:

{"success":false,"errors":["Required parameter missing: account"]}

这是我的程序:

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

import org.apache.commons.codec.binary.Hex;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import com.coinbase.api.Coinbase;
import com.coinbase.api.CoinbaseBuilder;

public class TransactionExample {

    static String API_KEY = "MY API KEY";

    static String API_SECRET = "MY API SECRET";

    public static String getHttp(String url, String body)
            throws InvalidKeyException, NoSuchAlgorithmException,
            ClientProtocolException, IOException {

        String nonce = String.valueOf(System.currentTimeMillis());
        String message = nonce + url + (body != null ? body : "");

        Mac mac = Mac.getInstance("HmacSHA256");
        mac.init(new SecretKeySpec(API_SECRET.getBytes(), "HmacSHA256"));
        String signature = new String(Hex.encodeHex(mac.doFinal(message.getBytes())));

        HttpRequestBase request;
        if (body == null || body.length() == 0)
            request = new HttpGet(url);
        else {
            HttpPost post = new HttpPost(url);
            post.setEntity(new StringEntity(body));
            request = post;
        }
        request.setHeader("ACCESS_KEY", API_KEY);
        request.setHeader("ACCESS_SIGNATURE", signature);
        request.setHeader("ACCESS_NONCE", nonce);

        HttpClient httpClient = HttpClientBuilder.create().build();
        HttpResponse response = httpClient.execute(request);

        HttpEntity entity = response.getEntity();
        if (entity != null)
            return EntityUtils.toString(entity);
        return null;
    }
    
    public static void main(String[] args) throws InvalidKeyException, NoSuchAlgorithmException, ClientProtocolException, IOException{
        
        System.out.println(getHttp("https://api.coinbase.com/v1/accounts", "{'account':{'name':'Savings Wallet'}}")); 
    }
}

请帮忙!

当然,我们将不胜感激!

【问题讨论】:

    标签: java api bitcoin coinbase-api


    【解决方案1】:

    您需要在此处将占位符文本替换为您的实际 API 密钥:

     static String API_KEY = "MY API KEY";
    
     static String API_SECRET = "MY API SECRET";
    

    您可以通过https://www.coinbase.com/settings/api 获取它们。

    不过,如果您刚刚开始,我建议您先使用 Sandbox API 进行测试,以避免任何安全风险。如果您的 API 密钥有权从您的帐户购买/出售或汇款,任何拥有它们的人都可以这样做。

    使用沙盒 API 时,您需要将 URL 从 https://api.coinbase.com/v1/accounts 更改为 https://api.sandbox.coinbase.com/v1/accounts

    此外,我们还发布了v2 of our API,它更加出色,但需要对该脚本进行一些其他修改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-05
      • 1970-01-01
      • 1970-01-01
      • 2018-10-28
      • 2018-12-01
      • 2016-06-29
      • 2018-06-20
      相关资源
      最近更新 更多