Quickstart guide

This guide should help you install and utilize LoginRadius and its feature set quickly and painlessly. For more examples, please see examples.

Install

Prerequisites

You will need at least Python - 2.7 or greater. LoginRadius module utilizes the namedtuple from the collections library and the import_module from importlib.

From Package

Using pip

pip install loginradius

or with easy_install

easy_install loginradius

From Source

You can download the latest version from PyPI

  • Unzip/untar the files.
  • Browse to the directory that you extracted the files to.
  • Run:
python setup.py install

To install the LoginRadius module.

Using the LoginRadius Object

import the class

from LoginRadius import LoginRadius

When you initialise your application, you will need to set your API Secret. This can be found in your control panel under your dashboard:

https://secure.loginradius.com/account#dashboard

When your Python application first starts up, you should set your API Secret once and only once

LoginRadius.API_SECRET = "some-really-obscure-string"

When you receive a callback from LoginRadius after a user has authenticated with their provider it will come with a token parameter. For example, with python in CGI we can do:

import cgi
arguments = cgi.FieldStorage()
token = arguments.getvalue('token')

This is highly dependent on your framework. You should browse some of our Examples and Use Cases for one that fits with your web framework and code flow.

We can now construct a LoginRadius object with respect to this token.

login = LoginRadius(token)

Doing so will make an HTTP request to LoginRadius for the access token. Not to be confused with the token we just received from our callback. This new token is the basis for all API calls to LoginRadius.

With our newly constructed object, we can perform any API call listed in the online API help document. As long as your plan is setup to do so! For example, the basic profile data is available to anyone.

http://api.loginradius.com/help/

We can access the profile information from the login object as a namedtuple.

if login.access.valid():
    print ("Hello there, " + login.user.profile["FirstName"] + ".")

We first check to see if our token hasn’t expired. Be wary that storing a LoginRadius object for too long may cause the token to become invalid. The default time, at the time of writing this guide, is fifteen minutes.

The next line of code embedded in the if statement prints the user’s first name.

This data is normalized across all data providers and is stored as a python dictionary to adapt to the API if changes are made at a later date. To view all up to date items available to you in the dictionary, visit:

http://www.loginradius.com/datapoints/

The thought process behind the LoginRadius object is to provide easily accessible functions with minimal arguments. It only loads data when needed.

Breaking Down the LoginRadius Object

Like our previous example, profile is not the only attribute available to you.

api

This should only be used in cases where you want direct access to the LoginRadiusAPI object without our wrapper. It is highly advised against using this attribute at all.

The api attribute is class of: LoginRadius.LoginRadiusAPI

access

Contains useful information about the access token.

expire

A string containing the date when this access token is no longer valid.

raw

A dictionary containing the raw JSON response from LoginRadius for the token.

token

This is our access token. Essentially for every API call.

valid()

Invoking this will return a True or False boolean for if the access token is still valid. It is useful to check before making an API call. This method will only compare the stored expired attribute date and current UTC time. It will not make a remote call to the server to validate.

error

A string of the last error message encountered.

settings

HTTP library settings for encoding requests.

library

Stores a string of the HTTP library currently being used with the LoginRadius object. Currently, this value can either be ‘urllib2’ or ‘requests’. Please call _settings(library) and not this if you intend to change it.

urllib

imported module of urllib.

urllib2

imported module of urllib2.

json

imported module of json.

requests

imported module of requests

token

The original token from the callback.

user

Some of these attributes may not pull any data. Please check your endpoints at http://www.loginradius.com/datapoints/

All of these attributes, by default, set raw=False to normalize data.

profile

Information from the user’s profile with respect to the current provider.

photo

Photos with regards to the album_id attribute.

album_id

A string of the album_id to be set before retrieval.

check_in

Get a list of checked in places from this profile.

album

Get a list of albums available on this profile.

audio

Get a list of audio available on this profile.

video

Get a list of uploaded videos on this profile

contacts

Get a list of contacts, you can also specify a next_cursor attribute.

next_cursor

An optional string for the next cursor.

status

Get a list of status updated on this profile.

group

Get a list of groups from this profile.

event

Get a list of events from this profile.

mention

Get a list of mentions from this profile.

activity

Get a list of activities from this profile.

following

Get a list of following from this profile.

page

Get page data with respect to what this user’s profile can see.

page_name

A string containing the unique identifier for the page to fetch data from.

like

Get a list of likes from this profile.

status_update(status, title='', url='', imageurl='', caption='', description='')

Perform a status update on the profile on behalf of the user. Some of these arguments may be ignored depending on the provider.

direct_message(to, subject, message)

Direct message another user on behalf of this user.