Giter Club home page Giter Club logo

aweber-api-python-library's Introduction

About

The AWeber API Python Library allows you to quickly get up and running with integrating access to the AWeber API into your Python applications. This egg requires the python-oauth2 to handle the authentication.

Installation

This egg can be installed by checking out the source:

$ sudo python setup.py install

Or can be installed using easy_install:

$ easy_install aweber_api

Usage

To connect the AWeber API Python Libray, you simply include the main class, AWeberAPI in your application, then create an instace of it with your application's consumer key and secret:

from aweber import AWeberAPI
aweber = AWeberAPI(consumer_key, consumer_secret)
account = aweber.get_account(access_token, token_secret)

for list in account.lists:
    print list.name

Getting request tokens / access tokens

You can also use the AWeberAPI object to handle retrieving request tokens:

from aweber import AWeberAPI
aweber = AWeberAPI(consumer_key, consumer_secret)
request_token, request_token_secret = aweber.get_request_token(callback_url)
print aweber.authorize_url

As well as access tokens:

from aweber import AWeberAPI
aweber = AWeberAPI(consumer_key, consumer_secret)
aweber.user.verifier = verifier
aweber.user.request_token = request_token
aweber.user.token_secret = request_token_secret
access_token, access_token_secret = aweber.get_access_token()

Full Pylons example

Here is a simple Pylons example that uses the AWeber API Python Library to get a request token, have it authorized, and then print some basic stats about the web forms in that user's lists:

from pylons import session, request, tmpl_context as c
from pylons.controllers.util import redirect 

from awebertest.lib.base import BaseController, render

from aweber_api import AWeberAPI

url = 'http://localhost:5000'
consumer_key = "vjckgsr5y4gfOa3PWnf"
consumer_secret = "u3sQ7vGGJBfds4q5dfgsTESi685c5x2wm6gZuIj"
class DemoController(BaseController):

    def __before__(self):
        self.aweber = AWeberAPI(consumer_key, consumer_secret)

    def index(self):
        token, secret = self.aweber.get_request_token(url+'/demo/get_access')
        session['request_token_secret'] = secret
        session.save()
        redirect(self.aweber.authorize_url)

    def get_access(self):
        self.aweber.user.request_token = request.params['oauth_token']
        self.aweber.user.token_secret = session['request_token_secret']
        self.aweber.user.verifier = request.params['oauth_verifier']
        session['token'], session['secret'] = self.aweber.get_access_token()
        session.save()
        redirect(url+'/demo/show')

    def show(self):
        c.account = self.aweber.get_account(session['token'], session['secret'])
        return render('data.mako')

In `data.mako`:

<!DOCTYPE html>
<html lang="en">
    <body>
        <h1>Web Forms</h1>
        % for list in c.account.lists:
        <b>List Id:</b> ${list.id}, name: ${list.name}<br />
        <b>Currently has:</b> ${len(list.web_forms)} web forms
        <ul>
        % for form in list.web_forms:
            <li>Form Id: ${form.id}, name: ${form.name}</li>
        % endfor
        </ul>
        % endfor
    </body>
</html>

aweber-api-python-library's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.