0

我正在尝试使用我的测试 API 密钥创建一个新的测试域,但我收到一个“无效密钥”错误。我可以执行版本检查代码,但不能执行域代码?

<?php
// Library installed from PEAR
require_once 'XML/RPC2/Client.php';

$apikey = 'xxxxxxx';

$domain = "mydomain.net";
$domain_api = XML_RPC2_Client::create(
    'https://rpc.gandi.net/xmlrpc/',
    array( 'prefix' => 'domain.' )
);
$result = $domain_api->available($apikey, array($domain));
print_r($result);
/*
Array
(
    [mydomain.net] => pending
)
*/
while ( $result[$domain] == 'pending') {
    usleep(700000);
    $result = $domain_api->available($apikey, array($domain));
}
//print_r($result);
/*
Array
(
    [mydomain.net] => unavailable
)
*/

// dump the result
print_r( $result );
?>

error:

Fatal error: Uncaught exception 'XML_RPC2_FaultException' with message 'Error on object : OBJECT_ACCOUNT (CAUSE_NORIGHT) [Invalid API key]' in /home2/path/php/XML/RPC2/Backend/Xmlrpcext/Client.php:131 Stack trace: #0 /home2/path/public_html/buydomain/index.php(66): XML_RPC2_Backend_Xmlrpcext_Client->__call('can_associate_d...', Array) #1 /home2/path/public_html/buydomain/index.php(66): XML_RPC2_Backend_Xmlrpcext_Client->can_associate_domain('My_KEY...', 'FLN123-GANDI', Array) #2 {main} thrown in /home2/path/php/XML/RPC2/Backend/Xmlrpcext/Client.php on line 131
4

1 回答 1

1

这是一个老问题,但我会回答任何绊倒这个问题的人的利益。根据Gandi API 文档,您不能直接调用名为“create”的方法。API 的其他部分也是如此,例如contact.create()。

这是 Gandi 自己的 PHP 示例:

    <?php
    $domain_spec = array(
        'owner' => 'FLN123-GANDI',
        'admin' => 'FLN123-GANDI',
        'bill' => 'FLN123-GANDI',
        'tech' =>'FLN123-GANDI',
        'nameservers' => array('a.dns.gandi-ote.net', 'b.dns.gandi-ote.net',
                               'c.dns.gandi-ote.net'),
        'duration' => 1);
    $op = $domain_api->__call('create', array($apikey, 'mydomain.net',
        $domain_spec));
    ?>

如您所见,$domain_api->create($apikey,'mydomain.net',$domain_spec)变为$domain_api->__call('create', array($apikey,'mydomain.net',$domain_spec))

于 2016-01-26T10:53:28.950 回答