0

海我正在尝试集成 Google Adword API .. 我在 MCC(我的客户中心)帐户下没有任何开发者令牌。

我正在使用此代码...但它不起作用如果您对此问题有任何答案,请帮助我...提前致谢

<?php 
require_once 'Google/Api/Ads/AdWords/Lib/AdWordsUser.php';

$username = "abc@mail.com";
$password = "abc";
$currencyCode = "USD";
$developerToken = "$username++$currencyCode";

$user = new AdWordsUser(null, $username, $password, $developerToken);
$user->SetDefaultServer("https://adwords-sandbox.google.com/");
$user->LogAll();
$user->SetClientId(null);

try {
    $campaignService = $user->GetService("CampaignService", 'v201306');
    $page = $campaignService->get(new Selector());
} catch (Exception $e) {

}

$managedCustomerService = $user->GetService('ManagedCustomerService', 'v201306');
$selector = new Selector();
$selector->fields = array('Login', 'CustomerId', 'Name');
$page = $managedCustomerService->get($selector);

$accounts = array();
foreach ($page->entries as $account) {
    if ($account->customerId > 0) {
        $accounts[] = $account;
    }
}

foreach ($accounts as $account) {
    print "Customer ID: {$account->customerId}\n";
}

$customerId = $accounts[0]->customerId;
$user->SetClientId($customerId);

$budgetService = $user->GetService('BudgetService', 'v201306');

$budget = new Budget();
$budget->name = 'Test Budget #' . time();
$budget->period = 'DAILY';
$budget->amount = new Money((float) 10000000);
$budget->deliveryMethod = 'STANDARD';

$operations = array();

$operation = new BudgetOperation();
$operation->operand = $budget;
$operation->operator = 'ADD';
$operations[] = $operation;

$result = $budgetService->mutate($operations);
$budget = $result->value[0];

$campaignService = $user->GetService("CampaignService", 'v201306');

$campaign = new Campaign();
$campaign->name = "Test Sandbox Account #" + time();
$campaign->status = "ACTIVE";
$campaign->biddingStrategy = new ManualCPC();

$campaign->budget = new Budget();
$campaign->budget->budgetId = $budget->budgetId;

$networkSetting = new NetworkSetting();
$networkSetting->targetGoogleSearch = TRUE;
$campaign->networkSetting = $networkSetting;

$campaign->settings = array(new KeywordMatchSetting(false));

$operation = new CampaignOperation();
$operation->operand = $campaign;
$operation->operator = 'ADD';

$operations = array($operation);
$result = $campaignService->mutate($operations);

print_r($result);
?>

我收到此错误::

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://adwords-sandbox.google.com//api/adwords/mcm/v201306/ManagedCustomerService?wsdl' : failed to load external entity "https://adwords-sandbox.google.com//api/adwords/mcm/v201306/ManagedCustomerService?wsdl" in /home/profiles/public_html/testing/seoteam/q/src/Google/Api/Ads/Common/Lib/AdsSoapClient.php:169 Stack trace: #0 /home/profiles/public_html/testing/seoteam/q/src/Google/Api/Ads/Common/Lib/AdsSoapClient.php(169): SoapClient->SoapClient('https://adwords...', Array) #1 /home/profiles/public_html/testing/seoteam/q/src/Google/Api/Ads/AdWords/Lib/AdWordsSoapClient.php(53): AdsSoapClient->__construct('https://adwords...', Array, Object(AdWordsUser), 'ManagedCustomer...', 'https://adwords...') #2 /home/profiles/public_html/testing/seoteam/q/src/Google/Api/Ads/AdWords/v201306/ManagedCustomerService.php(3660): AdWordsSoapClient->__construct('https://adwords...', Array, Object(AdWordsUser), 'ManagedCustomer...', 'https://adwor in /home/profiles/public_html/testing/seoteam/q/src/Google/Api/Ads/Common/Lib/AdsSoapClient.php on line 169
4

2 回答 2

2

Adwords API 沙盒功能已弃用。您可以在等待令牌获得批准时使用测试帐户:测试帐户文档

于 2013-09-05T07:35:29.457 回答
0

如果即使使用测试帐户仍然出现此错误,请在https://stackoverflow.com/a/41622876/674965查看我的答案

于 2017-01-12T21:02:13.527 回答