Php Google Cloud DNS服务-entity.change参数是必需的,但缺少
下面的代码使用Google的PHP API客户端,我收到了这个响应 Google_Service_异常,消息为“调用POST时出错:(400)“entity.change”参数是必需的,但已丢失 其中PROJECT-NAME和DNSZONE是我的项目和区域Php Google Cloud DNS服务-entity.change参数是必需的,但缺少,php,dns,google-cloud-platform,google-api-client,google-cloud-dns,Php,Dns,Google Cloud Platform,Google Api Client,Google Cloud Dns,下面的代码使用Google的PHP API客户端,我收到了这个响应 Google_Service_异常,消息为“调用POST时出错:(400)“entity.change”参数是必需的,但已丢失 其中PROJECT-NAME和DNSZONE是我的项目和区域 $client_email = MYCLIENT; $private_key = file_get_contents('config/credentials/KEY.p12'); $scopes = array('https://www.go
$client_email = MYCLIENT;
$private_key = file_get_contents('config/credentials/KEY.p12');
$scopes = array('https://www.googleapis.com/auth/ndev.clouddns.readwrite');
$project = "PROJECT-NAME";
$managedZone = "DNSZONE";
$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 = "testing.DNSZONE.net.";
$resource->rrdatas[] = "testing.otherhost.com.";
$resource->ttl = 800;
$resource->type = "CNAME";
$dns = new Google_Service_Dns($client);
$change = new Google_Service_Dns_Change();
$change->kind = "dns#change";
$change->setAdditions($resource);
$dns->changes->create($project,$managedZone,$change);
对于如何设置此参数,我有点困惑。或者我现在的位置来定义它。为了澄清答案,setAdditions需要一个数组
$change->setAdditions([ $resource ]);
经过6个小时的战斗,我终于明白了,我需要将我添加的内容打包成一个数组。错误消息是神秘的,没有帮助。是引发错误的rrdatas[]数组吗?我需要将我的Google\u服务\u Dns\u资源记录集包装在一个数组中。我很快会修改并给出答案。