Hi Bikram,

Perhaps an example in Perl works for you, it shouldn't be difficult to adapt 
this PHP code 
example<http://code.google.com/p/google-api-adwords-php/source/browse/trunk/examples/v201101/GetRelatedKeywords.php>from
 the Perl code.

Best,

-David Torres - AdWords API Team

-----------------------------------------------------

#!/usr/bin/perl -w
#
# Copyright 2011, Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This example gets keywords related to a seed keyword.
#
# Tags: TargetingIdeaService.get
# Author: David Torres <api.davidtor...@gmail.com>

use strict;
use lib "../../lib";

use Google::Ads::AdWords::Client;
use Google::Ads::AdWords::Logging;
use Google::Ads::AdWords::v201101::CountryTarget;
use Google::Ads::AdWords::v201101::CountryTargetSearchParameter;
use Google::Ads::AdWords::v201101::Keyword;
use Google::Ads::AdWords::v201101::KeywordMatchTypeSearchParameter;
use Google::Ads::AdWords::v201101::Paging;
use Google::Ads::AdWords::v201101::RelatedToKeywordSearchParameter;
use Google::Ads::AdWords::v201101::TargetingIdeaSelector;
use Google::Ads::Common::MapUtils;

# Log SOAP XML request and response.
Google::Ads::AdWords::Logging::enable_soap_logging();

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({version => "v201101"});

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Create seed keyword.
my $seed_keyword = Google::Ads::AdWords::v201101::Keyword->new({
  text => "mars cruise",
  matchType => "BROAD"
});

# Create country target.
my $country = Google::Ads::AdWords::v201101::CountryTarget->new({
  countryCode => 'US'
});

# Create selector.
my $selector = Google::Ads::AdWords::v201101::TargetingIdeaSelector->new({
  requestType => "IDEAS",
  ideaType => "KEYWORD",
  requestedAttributeTypes => ["CRITERION",
                              "AVERAGE_TARGETED_MONTHLY_SEARCHES",
                              "COMPETITION",
                              "GLOBAL_MONTHLY_SEARCHES"],
});

# Set selector paging (required for targeting idea service).
my $paging = Google::Ads::AdWords::v201101::Paging->new({
  startIndex => 0,
  numberResults => 10
});
$selector->set_paging($paging);

# Create related to keyword search parameter.
my $keyword_search_parameter =
    Google::Ads::AdWords::v201101::RelatedToKeywordSearchParameter->new({
      keywords => [$seed_keyword]
    });

# Country target search parameter.
my $country_target_search_parameter =
    Google::Ads::AdWords::v201101::CountryTargetSearchParameter->new({
      countryTargets => [$country]
    });

# Create keyword match type search parameter to ensure unique results.
my $keyword_match_type =
    Google::Ads::AdWords::v201101::KeywordMatchTypeSearchParameter->new({
      keywordMatchTypes => ["BROAD"]
    });
$selector->set_searchParameters([$keyword_search_parameter,
                                 $keyword_match_type,
                                 $country_target_search_parameter
                                 ]);

# Get related keywords.
my $page = $client->TargetingIdeaService()->get({selector => $selector});

# Display related keywords.
if ($page->get_entries()) {
  foreach my $targeting_idea (@{$page->get_entries()}) {
    my $data =
        Google::Ads::Common::MapUtils::get_map($targeting_idea->get_data());
    my $keyword = $data->{"CRITERION"}->get_value();
    my $average_monthly_searches =
        $data->{"AVERAGE_TARGETED_MONTHLY_SEARCHES"}->get_value()?
        $data->{"AVERAGE_TARGETED_MONTHLY_SEARCHES"}->get_value():0;
    my $competition =
        $data->{"COMPETITION"}->get_value()?
        $data->{"COMPETITION"}->get_value():0;
    my $global_monthly_searches =
        $data->{"GLOBAL_MONTHLY_SEARCHES"}->get_value()?
        $data->{"GLOBAL_MONTHLY_SEARCHES"}->get_value():0;
    printf "Keyword with text \"%s\", match type \"%s\", and average monthly 
" .
           "search volume \"%s\", competition \"%s\" was found.\n", 
$keyword->get_text(),
           $keyword->get_matchType(), $average_monthly_searches, 
$competition;
  }
} else {
  print "No related keywords were found.\n";
}

-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
http://adwordsapi.blogspot.com
http://groups.google.com/group/adwords-api
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en

Reply via email to