GithubHelp home page GithubHelp logo

zincr0 / django-twitter-oauth Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cmsimike/django-twitter-oauth

0.0 2.0 0.0 135 KB

Example of how to authenticate against Twitter oAuth using Django

Home Page: http://cmsimike.com

Python 100.00%

django-twitter-oauth's Introduction

django-twitter-oauth (forked from http://github.com/henriklied/django-twitter-oauth)

(Original snippet based on Simon Willison's Fire Eagle views )

I wanted to learn Python and Django so I decided to work on a web app in my free time. What I wanted to do included Twitter authentication and all information I found I felt were bits and pieces of the full puzzle, or parts were a bit out of date. I put everything I could together into a Django app I forked and am releasing it back. Thank you to all those that have code in this mashup. I am still in the middle of working on it so it may change, possibly significantly, over time. Give me some time to work out the kinks but I am confident that it works well.

Requirements

Installation

Add the 'twitter_app' directory somewhere on your 'PYTHONPATH', put it into 'INSTALLED_APPS' in your settings file. Fill in your CONSUMER_KEY and CONSUMER_SECRET in your settings file.

  • Add this line to your Django project's urlconf: url(r'^twitter/', include('twitter_app.urls')), By default, things should just work (as long as you specify the proper template location and what not). To use this in a production-type application, you are going to want to specify two settings in your settings.py file: TWITTER_AUTH_HOME - the named url pattern of where your home view is (useful when the user logs out, for instance) TWITTER_AUTH_AUTHENTICATED - the named url pattern of where you are sent when you are redirected back after being authenticated by twitter or if you try to access a page once you are already logged in.

I've added a TwitterAuthUserProfile.py file that you can extend in your application to add supplemental user profile fields. If you don't require anything extra, you can extend TwitterAuthUserProfile and leave it blank. If you are specifying a Meta inner class, set abstract = False. At the bottom of your app specific profile class, put:

def create_user_profile(sender, instance, created, **kwargs):
	if created:
		profile, created = <YOUR_APP_PROFILE>.objects.get_or_create(user=instance)

post_save.connect(create_user_profile, sender=User)

Now you should be good to go!

API Usage

from twitter_auth.util.utils import *

Then with an authenticated user in the request object:

#This gets the authenticated twitter.Api object
api = get_twitter_api_from_request(request)
users = api.GetFriends()

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.