[英]I couldn't connect to Google calender api using v3 php client library
[英]Google Adword PHP client library couldn't connect to host
我正在努力將我的網站連接到Google Adwords,以根據我網站上的產品創建廣告和廣告系列。 我嘗試通過發送直接curl請求進行連接並解析收到的SOAP響應。 但這對於每個請求來說都變得太復雜了。 因此,我嘗試使用Google Code中提供的PHP客戶端庫。 但是,所有示例均無法正常工作。 我更改了auth.ini文件中的用戶帳戶詳細信息,但仍在執行它說的示例文件時
無法獲取authToken。 原因: 無法連接到主機 “。
我嘗試在不同的服務器上運行腳本,但仍然遇到相同的錯誤。
以下是從Google adwords獲取所有廣告的代碼,這是客戶端庫中的示例文件
$path = dirname(__FILE__) . '/../../src';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once 'Google/Api/Ads/AdWords/Lib/AdWordsUser.php';
try {
// Get AdWordsUser from credentials in "../auth.ini"
// relative to the AdWordsUser.php file's directory.
$user = new AdWordsUser();
// Log SOAP XML request and response.
$user->LogDefaults();
// Get the AdGroupAdService.
$adGroupAdService = $user->GetAdGroupAdService();
$adGroupId = (float) '01';
// Create selector.
$selector = new Selector();
$selector->fields = array('Id', 'AdGroupId', 'Status');
$selector->ordering = array(new OrderBy('Id', 'ASCENDING'));
// Create predicates.
$adGroupIdPredicate = new Predicate('AdGroupId', 'IN', array($adGroupId));
// By default disabled ads aren't returned by the selector. To return them
// include the DISABLED status in a predicate.
$statusPredicate =
new Predicate('Status', 'IN', array('ENABLED', 'PAUSED', 'DISABLED'));
$selector->predicates = array($adGroupIdPredicate, $statusPredicate);
// Get all ads.
$page = $adGroupAdService->get($selector);
// Display ads.
if (isset($page->entries)) {
foreach ($page->entries as $adGroupAd) {
printf("Ad with id '%s', type '%s', and status '%s' was found.\n",
$adGroupAd->ad->id, $adGroupAd->ad->AdType, $adGroupAd->status);
}
} else {
print "No ads were found.\n";
}
} catch (Exception $e) {
echo 'Inside catch exception';
print $e->getMessage();
}
並在settings.ini文件中
DEFAULT_SERVER =“ https://adwords-sandbox.google.com”
; AUTH_SERVER = "<SERVER>"
在auth.ini文件中,正確設置了我的Google帳戶的用戶名和密碼。
有人可以幫我解決此問題。
謝謝
這是AUTH_SERVER
設置,而不是DEFAULT_SERVER
,它指示將身份驗證請求發送到的位置。 該名稱應位於settings.ini
的底部,但通常會被注釋掉,以便使用https://www.google.com
的默認設置。 您應該檢查AUTH_SERVER
是否已被注釋掉,並且可以連接到https://www.google.com
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.