Google Adword API + PHP

时间:2013-09-04 10:44:23

标签: php soap google-adwords

Hai我正在尝试整合Google Adword API ..我在MCC(我的客户中心)帐户下没有任何devloper令牌。

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

<?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

2 个答案:

答案 0 :(得分:2)

不推荐使用Adwords API沙箱功能。您可以在等待令牌获得批准时使用测试帐户:Test accounts documentation

答案 1 :(得分:0)

如果即使使用测试帐户仍然会出现此错误,请在here

上查看我的回答