簡體   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