繁体   English   中英

Google Adword API + PHP

[英]Google Adword API + PHP

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM