1

我正在尝试使用 PHP Coinbase API。我已经有一个 API 密钥和 OAuth 密钥。我已经设置了我的网络服务器。另外,我已经在 GitHub 上下载了这个库,但我仍然无法让它工作。

每次我使用此代码时,它都会返回:

string(213) "{"error":"invalid_grant","error_description":"提供的授权授权无效、过期、已撤销、与授权请求中使用的重定向 URI 不匹配,或已发布给另一个客户端。" }"

相关代码

$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)
4

1 回答 1

0

您应该做的第一件事是访问身份验证端点并获取身份验证代码,然后将其发回并获取访问令牌作为响应。

通常,请求应如下所示:

   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 完全匹配。

于 2018-09-20T14:42:43.147 回答