我想使用 php api 向谷歌云 dns 添加额外的 cname 记录。通过 Web 控制台添加的 sub1.example.com 和 sub2.example.com 的 cname 记录已经存在。但我得到一个错误
资源记录集“entity.change.additions[0]”无效,因为 DNS 名称为“example.com。” 可能有一个 CNAME 资源记录集或其他类型的资源记录集,但不能同时拥有。
<?php
require '../autoload.php';
$client_email = CEMAIL;
$private_key = file_get_contents(PKEY);
$scopes = array('https://www.googleapis.com/auth/ndev.clouddns.readwrite');
$project = PNAME;
$managedZone = "example-com";
$creds = new Google_Auth_AssertionCredentials($client_email,$scopes,$private_key);
$client = new Google_Client();
$client->setAssertionCredentials($creds);
$resource = new Google_Service_Dns_ResourceRecordSet();
$resource->kind = "dns#resourceRecordSet";
$resource->name = "example.com.";
$resource->rrdatas[] = "sub3.example.com.";
$resource->ttl = 300;
$resource->type = "CNAME";
$dns = new Google_Service_Dns($client);
$change = new Google_Service_Dns_Change();
$change->kind = "dns#change";
$change->setAdditions([$resource]);
$r=$dns->changes->create($project,$managedZone,$change);
echo '<pre>'.print_r($r,true).'</pre>';
?>
我也找不到使用 php api 列出现有 cname 记录的方法,因为这会给我这里答案的线索。有谁知道如何检索这些,到目前为止的代码
<?php
//include details from above
$dns = new Google_Service_Dns($client);
$r=$dns->managedZones->listManagedZones($project);
echo '<pre>'.print_r($r,true).'</pre>';
$r=$dns->managedZones->get($project,$managedZone);
echo '<pre>'.print_r($r,true).'</pre>';
?>
没有列出这些 cname 记录,尽管方法、get 和 listManagedZones 采用了一个额外的可选参数,但我找不到关于它的文档
来源:https ://github.com/google/google-api-php-client/blob/master/src/Google/Service/Dns.php 行:416、395
从文章继续:谷歌云 DNS 服务 - entity.change 参数是必需的,但缺少
-
https://developers.google.com/api-client-library/php/
https://developers.google.com/apis-explorer/#p/dns/v1/
https://support.google.com/cloud/answer/6158849?hl=en
https://cloud.google.com/dns/api/v1/resourceRecordSets#resource