谷歌云dns,php api,添加多个cname

谷歌云dns,php api,添加多个cname,php,dns,google-api-php-client,cname,google-cloud-dns,Php,Dns,Google Api Php Client,Cname,Google Cloud Dns,我想使用php api向google cloud dns添加额外的cname记录。已存在通过web控制台添加的sub1.example.com和sub2.example.com的cname记录。但是我犯了一个错误 资源记录集“entity.change.additions[0]”无效,因为DNS名称“example.com.”可能有一个CNAME资源记录集或其他类型的资源记录集,但不能同时有两个 <?php require '../autoload.php'; $client_emai

我想使用php api向google cloud 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>';

?>

此外,我也找不到一种使用PHPAPI列出现有cname记录的方法,因为这会给我这里答案的线索。到目前为止,有人知道如何检索这些代码吗

$resource = new Google_Service_Dns_ResourceRecordSet();
$resource->kind = "dns#resourceRecordSet";
$resource->name = "sub3.example.com.";       //sub
$resource->rrdatas[] = "example.com.";       //root domain

没有列出这些cname记录,尽管方法get和listmanagedzone带有一个附加的可选参数,但我找不到关于它的文档

资料来源: 电话号码:416395

第条的后续内容:

-


对于那些以后可能会找到这篇文章的人,根据这篇文章,我已经回答了我自己的问题

我注意到在文章的中间部分,邮件记录的列表在rrdatas字段中有根域,在资源的name属性中有子域,切换了两轮,然后

txt新增内容:

伊索

+


+1关于错误解释,在这里找到了
cnameResourceRecordSetConflict
:这“多少”提供了一个线索。。。
$resource = new Google_Service_Dns_ResourceRecordSet();
$resource->kind = "dns#resourceRecordSet";
$resource->name = "sub3.example.com.";       //sub
$resource->rrdatas[] = "example.com.";       //root domain
$del = new Google_Service_Dns_ResourceRecordSet();
$del->kind = "dns#resourceRecordSet";
$del->name = "example.com.";
$del->type = "TXT";
$del->ttl = 300;
$del->rrdatas[] = "\"test=test\"";

$add = new Google_Service_Dns_ResourceRecordSet();
$add->kind = "dns#resourceRecordSet";
$add->name = "example.com.";
$add->type = "TXT";
$add->ttl = 300;
$add->rrdatas[] = "\"test2=test2\"";
$add->rrdatas[] = "\"test3=test3\"";

$change->setAdditions([$add]);
$change->setDeletions([$del]);

$r=$dns->changes->create($project,$managedZone,$change);