Google 云 DNS 服务 - entity.change 参数是必需的但缺少

Google Cloud DNS Services - entity.change parameter is required but missing

使用 Google 的 PHP API 客户端使用以下代码,我收到了此回复。

Google_Service_Exception with message 'Error calling POST https://www.googleapis.com/dns/v1/projects/PROJECT-NAME/managedZones/DNSZONE/changes: (400) The 'entity.change' parameter is required but was missing.

其中 PROJECT-NAME 和 DNSZONE 是我的项目和区域。

$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 ]);