我沒有使用雲端DNS,但API似乎遵循其他服務的相同格式,所以我會嘗試給你一個它如何工作的想法。
PHP庫的文檔不是最好的,但看着source code和評論,你可以理解應該做什麼。
我不確定您之前是否使用過該庫,但第一步是創建並驗證一個Google_Client
對象。 Github上有例子。
您在Developers Console處創建憑證。選擇項目,然後在側欄上選擇API & 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);
我在尋找一個簡單的調用列表 - 又名$ dns-> AddDomain($ domain); $ dns-> CreateARecord($ domain,$ ip); $ dns-> CreateMXRecord($ domain,$ host,$ priotity);等等。他們的文檔是可怕的,並且通過閱讀成千上萬行代碼,通過猜測找到具體的函數調用 - 這裏有一個更好的方法。 – 2014-11-07 01:22:27
這真的很有幫助。我查看了這個例子,並重構了我的代碼,直到我意識到setAdditions正在接受一個Google_Service_Dns_ResourceRecordSet,但應該要求我將它包裝在一個數組中 - 並且最沒有幫助的錯誤消息「The'entity.change'參數是必需的但失蹤了。「在將我的添加包裝到一個數組後,這一切都奏效了! – 2015-08-21 04:45:38
Hi @ josh.chavanne,你可以分享一下數組格式。我也面臨同樣的問題。無法調試相同。 – Sreenath 2015-08-23 11:47:48