Hello,
I took the ruby on rails example, and tried to add to it a view which is
displaying the keywords from an AdGroup, I am able to get the keywords, and
the total no of keywords from a campaign but I don't know why I can not
display them in the view.
keyword model:
class Keyword
attr_reader :id
attr_reader :criteriaType
attr_reader :keywordText
def initialize(api_campaign)
@id = api_campaign[:id]
@criteriaType = api_campaign[:criteriaType]
@keywordText = api_campaign[:keywordText]
end
def self.get_keywords_list(response)
result = {}
if response[:entries]
response[:entries].each do |api_keyword|
keyword = Keyword.new(api_keyword)
result[keyword.id] = keyword
end
end
return result
end
end
keyword_controller
class KeywordController < ApplicationController
PAGE_SIZE = 50
def index()
@selected_account = selected_account
if @selected_account
response = request_keywords_list('AdGroupID')
if response
@keywords = Keyword.get_keywords_list(response)
@keyword_count = response[:total_num_entries]
end
end
end
private
def request_keywords_list(ad_group_id)
logger.debug ad_group_id
api = get_adwords_api()
service = api.service(:AdGroupCriterionService, get_api_version())
selector = {
:fields => ['Id', 'CriteriaType', 'KeywordText'],
:ordering => [{:field => 'Id', :sort_order => 'ASCENDING'}],
:predicates => [{:field => 'AdGroupId', :operator => 'EQUALS',
:values => [ad_group_id]},
{:field => 'CriteriaType', :operator => 'EQUALS', :values =>
['KEYWORD']}],
:paging => {:start_index => 0, :number_results => PAGE_SIZE}
}
result = nil
begin
result = service.get(selector)
logger.debug service.get(selector)
rescue AdwordsApi::Errors::ApiException => e
logger.fatal("Exception occurred: %s\n%s" % [e.to_s, e.message])
flash.now[:alert] =
'API request failed with an error, see logs for details'
end
return result
end
end
keyword/index.html.erb
<h1>Keywords list</h1>
<% if @selected_account.nil? %>
<div class="notice">No account selected!</div>
<% else %>
<% if @keywords.nil? or @keywords.empty? %>
<ul><li>No keywords available.</ul>
<% else %>
<ul><li>Total number of keywords: <%= @keyword_count %></ul>
<table>
<tr>
<th>ID
<th>KeywordText
<th>CriteriaType
<% @keywords.each do |id, keyword| %>
<tr>
<td><%= keyword.id %>
<td><%= keyword.keywordText %>
<td><%= keyword.criteriaType %>
<% end %>
</table>
<% end %>
If someone can help me with some pointers, I'll be grateful.
Thank you
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.