PHP Coinbase 如何使用 API 使用 PHP 语言开始使用?
PHP Coinbase how to start using this API using PHP language?
我正在尝试使用 PHP Coinbase API。我已经有一个 API 密钥和 OAuth 密钥。我已经设置了我的网络服务器。另外,我已经在 GitHub 上下载了这个库,但我仍然无法使用它。
每次我使用这段代码时 returns:
string(213) "{"error":"invalid_grant","error_description":"The
provided authorization grant is invalid, expired, revoked, does not
match the redirection URI used in the authorization request, or was
issued to another client."}"
相关代码
$post = [
'grant_type' => 'authorization_code',
'code' => 'xxxxxx',
'client_id' => 'xxxxx',
'client_secret' => 'xxxx',
'redirect_uri' => 'https://sample/mybots/blockchain',
];
$ch = curl_init('https://api.coinbase.com/oauth/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
// execute!
$response = curl_exec($ch);
// close the connection, release resources used
curl_close($ch);
// do anything you want with your response
var_dump($response)
您应该做的第一件事是转到授权端点并获取授权代码,然后将其发回并获取访问令牌作为响应。
通常,请求应如下所示:
response_type
REQUIRED. Value MUST be set to "code".
client_id
REQUIRED. The client identifier as described in Section 2.2.
redirect_uri
OPTIONAL. As described in Section 3.1.2.
scope
OPTIONAL. The scope of the access request as described by
Section 3.3.
state
RECOMMENDED. An opaque value used by the client to maintain
state between the request and callback. The authorization
server includes this value when redirecting the user-agent back
to the client. The parameter SHOULD be used for preventing
cross-site request forgery as described in Section 10.12.
你可以在这里看到https://www.rfc-editor.org/rfc/rfc6749#section-4.1.1
确实在 Coinbase 文档中 https://developers.coinbase.com/docs/wallet/coinbase-connect/integrating
您已跳过该步骤,您正在尝试从 coinbase 文档上的第 3 步开始!
确保在 coinbase 上也正确配置了客户端。并且重定向 url 完全匹配。
我正在尝试使用 PHP Coinbase API。我已经有一个 API 密钥和 OAuth 密钥。我已经设置了我的网络服务器。另外,我已经在 GitHub 上下载了这个库,但我仍然无法使用它。
每次我使用这段代码时 returns:
string(213) "{"error":"invalid_grant","error_description":"The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."}"
相关代码
$post = [
'grant_type' => 'authorization_code',
'code' => 'xxxxxx',
'client_id' => 'xxxxx',
'client_secret' => 'xxxx',
'redirect_uri' => 'https://sample/mybots/blockchain',
];
$ch = curl_init('https://api.coinbase.com/oauth/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
// execute!
$response = curl_exec($ch);
// close the connection, release resources used
curl_close($ch);
// do anything you want with your response
var_dump($response)
您应该做的第一件事是转到授权端点并获取授权代码,然后将其发回并获取访问令牌作为响应。
通常,请求应如下所示:
response_type
REQUIRED. Value MUST be set to "code".
client_id
REQUIRED. The client identifier as described in Section 2.2.
redirect_uri
OPTIONAL. As described in Section 3.1.2.
scope
OPTIONAL. The scope of the access request as described by
Section 3.3.
state
RECOMMENDED. An opaque value used by the client to maintain
state between the request and callback. The authorization
server includes this value when redirecting the user-agent back
to the client. The parameter SHOULD be used for preventing
cross-site request forgery as described in Section 10.12.
你可以在这里看到https://www.rfc-editor.org/rfc/rfc6749#section-4.1.1
确实在 Coinbase 文档中 https://developers.coinbase.com/docs/wallet/coinbase-connect/integrating
您已跳过该步骤,您正在尝试从 coinbase 文档上的第 3 步开始!
确保在 coinbase 上也正确配置了客户端。并且重定向 url 完全匹配。