Sorry for the triple post, but figured someone might need this information.
To get monthly searches and average CPC for a keyword, follow these steps:
Before Starting:
1) Register a new Google account.
2) Do not sign up for AdWords, you will mess everything up.
3) Sign up for
www.google.com/adwords/myclientcenter/
5) Request Developer API Access under My Account > AdWords API Center
6) If you don't have that option under My Account, you messed up, make a new Google account and start over.
7) You now have a pending (unworking) developer key on that page when you revisit it. Keep that in mind, it's not youremail++USD[or your currency code].
8) Go to My Client Center home and create an account. This will be your test account.
9)
Click here to submit to Google that the account is a test account, and wait for approval.
10) Once that test account is approved, continue.
NOTE: Make sure you have credit card information under Billing > Billing Preferences. If you do not, you will return an error or this will simply not work! API calls for the AdWords API use to cost, but as of March 1, 2013, Google announced that there will be no charge for API calls. You are limited to 10,000 a day, however, under a Basic account. If you want to make unlimited calls, look into getting a Standard account. We will not cover that.
Also Note: Although normal API calls do not cost, you will still be charged for any advertisement you request via the API. If you're looking at this, you probably don't care about actually using the API for ad campaigns (but instead finding keyword search volume as well as CPC), so it doesn't matter.
After all of that:
1) Download the API framework at:
https://code.google.com/p/google-api-adwords-php/downloads/list
2) Follow the instructional video at: [ame="http://www.youtube.com/watch?v=Idvia4600_E"]Getting Started with the AdWords API PHP Client Library - YouTube[/ame] (make sure you change your settings).
3) Extract your framework into your developmental folder you're going to use. Change the default name of the main folder to "aw". Do not navigate to the inside of the folder before extracting, extract the folder that appears when you first open the file. It's going to have a long name, ignore that, extract it, and then change that long name to "aw".
4) Change your auth.ini file to your proper credentials, and if your developer account is not yet approved, uncomment clientId (by removing the ";" in front of it) to the clientId they emailed you for the test account. NOTE: The results of many of the scripts are going to be dummy stats, so you can just play with them until your account is approved. The results of the script I'm posting below is going to contain dummy stats.
(Auth file is at aw\src\Google\Api\Ads\AdWords\auth.ini, settings file is in the same directory).
5) Save the code below in the folder that your "aw" folder is in (do not put it in your "aw" folder).
PHP:
<?php
class keyword_tool_simplified{
function searches_and_cpc($keyword){
$depth = '/../../../';
define('SRC_PATH', 'aw/src/');
define('LIB_PATH', 'Google/Api/Ads/AdWords/Lib');
define('UTIL_PATH', 'Google/Api/Ads/Common/Util');
define('ADWORDS_UTIL_PATH', 'Google/Api/Ads/AdWords/Util');
define('ADWORDS_VERSION', 'v201302');
ini_set('include_path', implode(array(
ini_get('include_path'), PATH_SEPARATOR, SRC_PATH
)));
require_once LIB_PATH . '/AdWordsUser.php';
require_once UTIL_PATH . '/MapUtils.php';
$user = new AdWordsUser();
$user->LogAll();
$data = explode(" - ",self::GetKeywordIdeasExample($user,$keyword));
$result = array("searches" => $data[0], "cpc" => $data[1]);
return $result;
}
function GetKeywordIdeasExample(AdWordsUser $user,$keyword_data) {
$targetingIdeaService =
$user->GetService('TargetingIdeaService', ADWORDS_VERSION);
$keyword = '['.$keyword_data.']';
$selector = new TargetingIdeaSelector();
$selector->requestType = 'STATS';
$selector->ideaType = 'KEYWORD';
$selector->requestedAttributeTypes = array('KEYWORD_TEXT', 'SEARCH_VOLUME','AVERAGE_CPC');
$languageParameter = new LanguageSearchParameter();
$english = new Language();
$english->id = 1000;
$languageParameter->languages = array($english);
$relatedToQuerySearchParameter = new RelatedToQuerySearchParameter();
$relatedToQuerySearchParameter->queries = array($keyword);
$selector->searchParameters[] = $relatedToQuerySearchParameter;
$selector->searchParameters[] = $languageParameter;
$selector->paging = new Paging(0, 1);
do {
$page = $targetingIdeaService->get($selector);
if (isset($page->entries)) {
foreach ($page->entries as $targetingIdea) {
$data = MapUtils::GetMap($targetingIdea->data);
$keyword = $data['KEYWORD_TEXT']->value;
$search_volume = isset($data['SEARCH_VOLUME']->value)
? $data['SEARCH_VOLUME']->value : 0;
$average_cpc = isset($data['AVERAGE_CPC']->value)
? $data['AVERAGE_CPC']->value : 0;
return $search_volume." - $".$average_cpc;
}
}
$selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
} while ($page->totalNumEntries > $selector->paging->startIndex);
}
}
$keyword_tool = new keyword_tool_simplified;
$result = $keyword_tool->searches_and_cpc("testing"); // testing is the keyword we're checking, change it to the keyword you want stats for.
echo "Monthly Searches: ".@$result["searches"];
echo "<BR>";
echo "Average CPC: ".@$result["cpc"];
?>
Please note, this has not been tested on a active developer account, only on a client test account. My account is not approved, so I can't verify whether or not the data is going to be exact searches or broad, nor can I guarantee that the CPC is going to work yet as it has returned $0 for every search I have done. I will modify this if there is any issues once I have an active developer / API account.
Hope this helped somebody.