简体   繁体   中英

Google Adword API + PHP

Hai I am trying to integrate Google Adword API .. I am not having any devloper token for under MCC (My client center) account .

I am using this code ... But its not working If you have any answer for this problem then please help me ... thanks in advance

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

I am getting this error ::

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

The Adwords API sandbox functionality is deprecated. You can use a test account while you wait for your token to be approved: Test accounts documentation

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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