0

我在 Google Developer 控制台中设置了计费和诸如此类的东西,并启用了 Cloud DNS APi,但它非常令人困惑,而且文档似乎让我在没有真实示例的情况下陷入困境。

我想要一个示例,说明如何使用来自 Github 的 google-api-php-client 脚本使用 Google Cloud DNS API 添加 DNS 条目、删除 DNS 条目和更新 DNS 条目。

我也不确定我应该为此使用什么凭据,因为似乎没有任何方法可以生成凭据——只有这个可计费服务的唯一应用程序 ID(无法更改)。

他们的文档指向stackoverflow,以解决有关使用此库的任何问题。

提前致谢。

4

1 回答 1

2

我没有使用过 Cloud DNS,但 API 似乎遵循与其他服务相同的格式,所以我将尝试让您了解它的工作原理。

PHP 库的文档不是最好的,但是查看源代码和注释您可以了解应该做什么。

我不确定您以前是否使用过该库,但第一步是创建和验证Google_Client对象。Github 上有例子。

您在Developers Console中创建凭据。选择项目,然后在侧边栏上选择 APIs & auth / Credentials。

下面的代码显然只是一个草稿,请检查库的源代码以查看所有可用的方法和选项。

<?php

// Assuming $client is a Google_Client instance that
// is already authenticated

$dns = new Google_Service_Dns($client);

$change = new Google_Service_Dns_Change();

$addition1 = new Google_Service_Dns_ResourceRecordSet();
// configure $addition1, check the methods on the lib

$deletion1 = new Google_Service_Dns_ResourceRecordSet();
// configure $deletion1, check the methods on the lib

$additions = array($addition1, ..., $additionN);
$deletions = array($deletion1, ..., $deletionN);

$change->setAdditions($additions);
$change->setDeletions($deletions);
// other settings on $change, check the lib

$dns->changes->create($project, $managedZone, $change);
于 2014-11-03T01:29:46.510 回答