英文:
Is there any way to integrate coinbase with java?
问题
以下是翻译好的内容:
我之前使用下面的 代码
获取 响应
,但是我一直在收到 403 错误
:
URL url = new URL("https://api.commerce.coinbase.com/checkouts");
Map map = new HashMap();
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
英文:
I was using below code
to get the response
but I Was getting the 403 error
URL url = new URL ("https://api.commerce.coinbase.com/checkouts");
Map map=new HashMap();
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
答案1
得分: 1
从 https://commerce.coinbase.com/docs/api/
大部分对商务 API 的请求必须使用 API 密钥进行身份验证。
创建 Coinbase Commerce 帐户后,您可以在设置页面上创建 API 密钥。
您需要向 API 提供一组最少的信息,以便它能够以成功代码 200
响应返回。
英文:
From https://commerce.coinbase.com/docs/api/
> Most requests to the Commerce API must be authenticated with an API
> key. You can create an API key in your Settings page after creating a
> Coinbase Commerce account.
You would need to provide minimal set of information to API in order for it to respond back with success code 200
.
答案2
得分: 0
是的,但看起来您提供的信息不够。还需要提供两个标题字段。这些字段分别是X-CC-Api-Key
(您的API密钥)和X-CC-Version
。请参阅下面的链接。
https://commerce.coinbase.com/docs/api/#introduction
可以使用addRequestProperty
将标题字段添加到HttpURLConnection
中。
https://docs.oracle.com/javase/8/docs/api/java/net/URLConnection.html#addRequestProperty-java.lang.String-java.lang.String-
URL url = new URL("https://api.commerce.coinbase.com/checkouts");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.addRequestProperty("X-CC-Api-Key", "YourSuperFancyAPIKey");
connection.addRequestProperty("X-CC-Version", "2018-03-22");
connection.setDoOutput(true);
您还需要注意使用的方法。在您的示例中,您提供了一个POST方法。这可能不是您想要的初始操作。如果您发送一个GET方法,您将收到一个包含所有检查的列表。这将是一个很好的起点。
https://commerce.coinbase.com/docs/api/#checkouts
- 使用GET方法检索检查列表
- 使用POST方法创建新的检查
- 使用PUT方法更新检查
- 使用DELETE方法删除检查
这种类型的API被称为REST。
英文:
Yes, but it looks like you aren't providing enough information. There are two header fields that need to be supplied as well. These are X-CC-Api-Key
which is your API key and X-CC-Version
. See the link below.
https://commerce.coinbase.com/docs/api/#introduction
Header fields can be provided to HttpURLConnection
using the addRequestProperty
https://docs.oracle.com/javase/8/docs/api/java/net/URLConnection.html#addRequestProperty-java.lang.String-java.lang.String-
URL url = new URL("https://api.commerce.coinbase.com/checkouts");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.addRequestProperty("X-CC-Api-Key", "YourSuperFancyAPIKey");
connection.addRequestProperty("X-CC-Version", "2018-03-22");
connection.setDoOutput(true);
You also want to be careful about what method you use. You are supplying a POST method in your example. This probably not what you want to start with. If you send a GET method you will receive back a list of all checks. This will be a good place to start.
https://commerce.coinbase.com/docs/api/#checkouts
- GET to retrieve a list of checkouts
- POST to create a new checkout
- PUT to update a checkout
- DELETE to delete a checkout
This type of API is known as REST.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论