Negative and wrong values from TargetingIdeaService PHP

184 views
Skip to first unread message

Jiří Zapletal

unread,
Apr 15, 2016, 11:47:31 AM4/15/16
to AdWords API Forum
Hi, I use PHP API v201603. If I make request via TargetingIdeaService It returns wrong values for SEARCH_VOLUME, AVERAGE_CPC and SEARCH_VOLUME, AVERAGE_CPC in TARGET_MONTHLY_SEARCHES only KEYWORD_TEXT is correct.

In the picture from Google AdWords -> Tools -> Keyword planner You can see 4 keywords "Test, auto, autoškola, fasgasg" 
  • test - Search volume: 12 100, CPC: 9,95 Kč
  • auto - Search volume: 27 100, CPC: 9,29 Kč
  • autoškola - Search volume: 4 400, CPC: 6,39 Kč
  • fasgasg - Search volume: -, CPC: -


In this second picture you can see dumped results returned from PHP API in my APP.


My problem is in different values from AdWords and my APP.
  • KW: fasgasg
    • CPC from AdWords: - (0, NULL, or something like that)
    • CPC from my APP: -4674422423092159488 (and if it is converted from microAmount it will be -4674422423092159488000000)
    • Search value from AdWords: - (0, NULL, or something like that)
    • Search value from my APP: 767580017206867942
  • KW: auto
    • CPC from AdW: 9,29 Kč
    • CPC from my APP: 8468354352673602560 (convert from microAmount - 8468354352673,602560)
    • Search volume from Adw: 27 100
    • Search volume from my APP: 492248457842398316
  • And more...
There is my PHP source code:
<?php

require_once '../vendor/autoload.php';

use Tracy\Debugger; Debugger::enable();


$queries = ['Test', 'Autoškola', 'Auto', 'fasgasg'];

$user = new AdWordsUser();
$user->SetClientCustomerId('224-971-6211');
$user->LogDefaults();


$targetingIdeaService = $user->GetService('TargetingIdeaService', 'v201603');


/*foreach ($queries as $key => $value) {
$queries[$key] = new Keyword($value, 'BROAD');
}*/

$selector = new TargetingIdeaSelector();

$selector->requestType = 'STATS';
$selector->ideaType = 'KEYWORD';
$selector->requestedAttributeTypes = ['KEYWORD_TEXT', 'SEARCH_VOLUME', 'AVERAGE_CPC', 'TARGETED_MONTHLY_SEARCHES'];

$relatedToQuerySearchParameter = new RelatedToQuerySearchParameter();
$relatedToQuerySearchParameter->queries = $queries;
$selector->searchParameters[] = $relatedToQuerySearchParameter;

/*$english = new Language();
$english->id = 1021; // CZ

$languageParameter = new LanguageSearchParameter();
$languageParameter->languages[] = $english;
$selector->searchParameters[] = $languageParameter;*/

$location = new Location();
$location->id = 2203; // ČR

$locationParameter = new LocationSearchParameter();
$locationParameter->locations[] = $location;
$selector->searchParameters[] = $locationParameter;


$networkSetting = new NetworkSetting();
$networkSetting->targetGoogleSearch = true;
$networkSetting->targetSearchNetwork = false;
$networkSetting->targetContentNetwork = false;
$networkSetting->targetPartnerSearchNetwork = false;

$networkSearchParameter = new NetworkSearchParameter();
$networkSearchParameter->networkSetting = $networkSetting;
$selector->searchParameters[] = $networkSearchParameter;

$selector->paging = new Paging(0, sizeof($queries));

$keywordStats = [];

do {
$page = $targetingIdeaService->get($selector);

if (isset($page->entries))
{
foreach ($page->entries as $targetingIdea)
{
$data = MapUtils::GetMap($targetingIdea->data);

$keywordStats[] = [
'keyword' => $data['KEYWORD_TEXT']->value,
'search_volume' => $data['SEARCH_VOLUME']->value,
'average_cpc' => $data['AVERAGE_CPC']->value->microAmount,
'target_monthly_searches' => $data['TARGETED_MONTHLY_SEARCHES']->value
];

Debugger::barDump($data['KEYWORD_TEXT']);
Debugger::barDump($data['SEARCH_VOLUME']);
Debugger::barDump($data['AVERAGE_CPC']);
Debugger::barDump($data['TARGETED_MONTHLY_SEARCHES']);
Debugger::barDump(NULL);

}
} else {
print "No keywords ideas were found.\n";
}

$selector->paging->startIndex += sizeof($queries);

} while ($page->totalNumEntries > $selector->paging->startIndex);


?>

<?php foreach ($keywordStats as $kw) { ?>

<h1>KW: <?= $kw['keyword'] ?></h1>
<p>Search volume: <?= $kw['search_volume']?></p>
<p>CPC: <?= $kw['average_cpc'] ?></p>

<?php } ?>

I will be very thankful if anybody can help me.

Anthony Madrigal

unread,
Apr 15, 2016, 5:10:12 PM4/15/16
to AdWords API Forum
Hi,

Looking at your code, it seems you have a STATS requestType. If you want the data to return similar to the Keyword Planner, you should use IDEAS instead.

Regards,
Anthony
AdWords API Team

Jiří Zapletal

unread,
Apr 16, 2016, 7:16:01 AM4/16/16
to AdWords API Forum
Thank you for your response.

I found in documentation that object TargetingIdeaService returns dummy data for Test Accounts.

Is there any way to turn-on PRODUCTION mode in PHP API and work with real data? I can't find anything about it.

Something like that: 
adwords = AdwordsApi::Api.new({
 
:authentication => {
     
:method => 'OAuth2',
     
:oauth2_client_id => 'INSERT_OAUTH2_CLIENT_ID_HERE',
     
:oauth2_client_secret => 'INSERT_OAUTH2_CLIENT_SECRET_HERE',
     
:developer_token => 'DEVELOPER_TOKEN',
     
:client_customer_id => '012-345-6789',
     
:user_agent => 'Ruby Sample'
 
},
 
:service => {
   
:environment => 'PRODUCTION'
 
}
})
But it is for Ruby.



Dne pátek 15. dubna 2016 23:10:12 UTC+2 Anthony Madrigal napsal(a):

Umesh Dengale

unread,
Apr 18, 2016, 10:05:45 AM4/18/16
to AdWords API Forum
Hello,

To make production AdWords API, you need to provide your production AdWords account Id to the client_customer_id in above code.  Please check out OAuth2.0 Ruby guide and AdWords-Readme document.

Regards,
Umesh, AdWords API Team.
Reply all
Reply to author
Forward
0 new messages