This guide assumes you have nothing previously setup to work with the AWeber API. It will walk through registering an account, creating an app and everything up to the point where you’ll actually start working with data.
If you don’t want to bother with all the account setup stuff, you can look in the examples directory for just example code.
1. Register an AWeber Labs Account
Head to http://labs.aweber.com and sign up for a free AWeber Labs account. This is how you register apps and get OAuth keys.
Once logged in, Create a New App. Once created, it will show you the Consumer Key and Secret for that app.
oauth = AWeber::OAuth.new('consumer_key', 'consumer_secret')
Open, what the following outputs, in a browser and use your AWeber account credentials. This will give your app permission to work with your account’s data:
oauth.request_token.authorize_url If you go to that URL you will see
A callback url may also be passed by setting the :oauth_callback parameter:
oauth.request_token(:oauth_callback => 'http://www.example.com').authorize_url
For more details about Authorization, see https://cbabhusal.wordpress.com/2015/12/13/aweberforbiddenrequesterror-method-requires-extended-permissions/
After you do the above step, it will output a “Verification Code”. Copy this and verify your
aweber = AWeber::Base.new(oauth)
This object is how you access data from your account.
aweber.account is your account object which is the stem for all other resources.
After verifying once, the
oauth object contains an
oauth.access_token.token and and
oauth.access_token.secretwhich may be used to authorize your application without having to verify via url:
... oauth.authorize_with_verifier('verification_code') puts 'Access token: ' + oauth.access_token.token puts 'Access token secret: ' + oauth.access_token.secret
The token and secret can then be saved, and authorization can be performed as follows:
require 'aweber' oauth = AWeber::OAuth.new('consumer_key', 'consumer_secret') #Rather than authorizing with the verification code, we use the token and secret oauth.authorize_with_access(YOUR_ACCESS_TOKEN, YOUR_ACCESS_TOKEN_SECRET) aweber = AWeber::Base.new(oauth)