我想添加额外的cname记录到google cloud dns使用php api。已存在通过web控制台添加的sub1.example.com和sub2.example.com的cname记录。但是我得到了一个错误
由于DNS名称‘example.com’,资源记录集'entity.change.additions‘无效。可以具有一个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 line:416395
后续文章:Google Cloud DNS Services - entity.change parameter is required but missing
-
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
发布于 2015-09-28 22:41:03
对于那些以后可能会发现这篇文章的人,我已经回答了我自己的问题,根据这篇文章
https://www.zeitgeist.se/2014/05/01/google-cloud-dns-how-to/
我在文章的中间注意到,邮件记录的清单在资源的rrdatas字段中有根域,在资源的name属性中有子域,切换了两轮和voila
$resource = new Google_Service_Dns_ResourceRecordSet();
$resource->kind = "dns#resourceRecordSet";
$resource->name = "sub3.example.com."; //sub
$resource->rrdatas[] = "example.com."; //root domaintxt添加:
$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);https://github.com/google/google-api-php-client/tree/master/examples
伊索。
+
https://stackoverflow.com/questions/32823671
复制相似问题