0

我正在努力将我的网站连接到 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 帐户的用户名和密码设置正确。

有人可以帮我解决这个问题。

谢谢

4

1 回答 1

0

指示身份验证请求被发送到哪里的是AUTH_SERVER设置,而不是。DEFAULT_SERVER这应该在底部,settings.ini但通常会被注释掉,以便使用默认设置https://www.google.com。您应该检查AUTH_SERVER已注释掉并且您可以连接到https://www.google.com.

于 2011-04-25T10:29:59.343 回答