11

我正在尝试根据他们在此处提供的 API 为 GoDaddy 开发客户端应用程序https://developer.godaddy.com 我有一个简单示例的问题,我正在尝试使用下一个 PHP 代码来检查域是否可用:

use GuzzleHttp\Client;
try {
    $client = new Client([
        'base_uri' => 'https://api.godaddy.com',
    ]);

    $responce = $client->get(
        '/v1/domains/available?domain=example.guru',
        [
            'headers' => [
                'Authorization' => "sso-key $myKey:$mySecret",
                'X-Shopper-Id' => "$myID",
                'Accept' => 'application/json',
            ]
        ]
    );
    echo $responce->getBody();
} catch (Exception $e) {
    echo $e->getMessage();
}

而且我一直收到错误:“客户端错误:401”。我在使用 cURL 库时遇到了同样的问题。我没有找到任何在线支持。我需要帮助,有人可以解释我应该如何在他们的 api 服务中授权吗?也许我需要发送任何其他 http 标头或其他参数?

4

3 回答 3

13

是您用于生产的密钥和秘密吗?当我完成这个过程时,默认情况下它会创建一个 TEST 密钥/秘密,我认为它是为了违背https://api.ote-godaddy.com

如果您使用的是生产密钥,请尝试通过以下命令执行手动 Curl 请求;就像是:

curl -H 'Authorization: sso-key {KEY}:{SECRET}' -H 'Content-Type: application/json' https://api.godaddy.com/v1/domains/available?domain=example.guru'

让我们知道结果如何!

于 2015-08-29T19:46:59.787 回答
5

The problem was that I was using TEST {KEY}:{SECRET} and set wrong URL.

For the test {KEY}:{SECRET} URL has to be: https://api.ote-godaddy.com.

Also the method for checking domain availability (/v1/domains/available) doesn't need parameter 'X-Shopper-Id' in header. It works well without it. With parameter X-Shopper-Id request returns error "NOT_FOUND: The specified shopperId could not be found"(but it's other problem, maybe I didn't activate some option)

So if to take into account all changes, the working code for checking domain availability with test key/secret should be like this:

use GuzzleHttp\Client;
try {
    $client = new Client([
        'base_uri' => 'https://api.ote-godaddy.com'
    ]);

    $responce = $client->get(
        '/v1/domains/available?domain=example.guru',
        [
            'headers' => [
                'Authorization' => "sso-key $myKey:$mySecret",
                'Accept' => 'application/json',
            ]
        ]
    );
    echo $responce->getBody();
} catch (Exception $e) {
    echo $e->getMessage();
}
于 2015-08-30T13:05:51.510 回答
0

我正在使用 php 和 curl。

$domain = "jaisinghverma.com";<br>
$apiURL = 'https://api.ote-godaddy.com/v1/domains/available?
domain='.$domain.'&checkType=FULL&forTransfer=false';<br>
$headers = array(
  'Accept: application/json',
  'Authorization: sso-key ?????????',
);<br>
$ch = curl_init();<br>
curl_setopt($ch, CURLOPT_URL, $apiURL);<br>
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<br>
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);<br>
$server_output = curl_exec ($ch);<br>
curl_close ($ch);<br>
print_r(json_decode($server_output));

上面的代码对我来说工作正常。

于 2017-12-01T12:27:54.303 回答