Ruby on Rails app using OAuth2 and AdWords API
Google’s AdWords API service lets developers design computer programs that
interact directly with the AdWords platform. With these applications,
advertisers and third parties can more efficiently — and creatively — manage
their large or complex AdWords accounts and campaigns.
This program adapts the AdWords on Rails sample application that demonstrated how to access the AdWords API from within a Ruby on Rails environment. It is based on the Google Ruby
AdWords API client library.
The application demonstrates the following:
AdWords Setup
AdWords Other
Reports & Measure Reports - https://developers.google.com/adwords/api/docs/guides/uireports
Setup Developer Account Links
IntelliJ IDE Config
Fix error: “No Rails found in SDK” IntelliJ
Edit Configurations > Click “+” > Select “Rails” > for “Ruby SDK” choose “Use other SDK” and select ‘RVM: ruby-2.4.1 [skag_server_rails_app]’
File > Project Structure > Project Settings > Project SDK > select ‘RVM: ruby-2.4.1 [skag_server_rails_app]’
File > Project Structure > Platform Settings > SDK > Select ‘RVM: ruby-2.4.1 [skag_server_rails_app]’ > Change “Gems bin directory” to the directory shown when you run which rails
from the project directory (but remove rails
from the end i.e. /Users/Me/.rvm/gems/ruby-2.4.1@skag_server_rails_app/bin
)
Fix error: Rails server launcher wasn’t found in project
Run Locally
Check Ruby 2.2 or later installed:
Update RubyGems http://railsapps.github.io/updating-rails.html
gem -v
gem update --system
Create Gemset with RVM
ruby -v
rvm list
rvm use ruby-2.4.1
rvm gemset create skag_server_rails_app2.4.1
rvm --ruby-version use 2.4.1@skag_server_rails_app2.4.1
rvm gemset list
rvm gemdir
Fix missing Bin directory
rake rails
bin
Install dependencies
gem install rails -v 5.1.2
gem install bundle
bundle install -V
Open PostgreSQL
Initialize local PostgreSQL schema:
rails db:create db:migrate RAILS_ENV="development"
Configure AdWords API settings:
```
subl config/adwords_api.yml
```
* Start the server. Open in browser:
```
rails server;
open http://localhost:3000
```
To access AdWords data the app needs to be granted access by a
logged in user. The user is automatically redirected to a page with login prompt
when not yet authorized.
After being prompted with say SKAG Server Rails wants to Manage your AdWords campaigns
, to grant access, click the ‘Proceed’ link. Ensure you are on the Google login
page, log in with your AdWords account credentials and select ‘Grant access’.
Note: Granting access to the application will only allow access to the AdWords
data for the account. Other services will not be accessible.
Once logged in you can retrieve the accounts list, select an account and browse
the campaigns list or download a report with the corresponding menu items.
To be able to use the AdWords API there are a few parameters that need to be
specified. The configuration file is located under the ‘config’ directory and
named adwords_api.yml.
For details regarding configuration directive please refer to the library
README.
This demo is capable of accessing production accounts. Although the app doesn’t
perform any mutate operations, it is best to be careful especially if modifying it to include additional functionality.