diff --git a/README.md b/README.md
index 6d48a0b..676100d 100644
--- a/README.md
+++ b/README.md
@@ -9,15 +9,11 @@ Even if you are not using this for a hackathon, Django Hackathon Starter is sure
-
-![Twitter Tweets](http://i.imgur.com/tHZrgoK.png)
+![API Examples](http://i.imgur.com/zFqKcVa.png)
Table of Contents
-----------------
@@ -34,10 +30,20 @@ Features
--------
* User Registration
* Sphinx Documentation
-* Django Nosetests
+* Django Nosetests
+* Integration with Django Rest Framework
* Basic Authentication with username and password
-* **OAuth 2.0 Authentication** for Github, LinkedIn and Instagram
-* **OAuth 1.0a Authentication** for Twitter and Tumblr
+* **OAuth 2.0 Authentication**
+ * Github
+ * LinkedIn
+ * Instagram
+ * Facebook
+ * Google+
+ * Dropbox
+ * Foursquare
+* **OAuth 1.0a Authentication**
+ * Twitter
+ * Tumblr
* **API Examples**
* Yelp API
* Github API
@@ -45,11 +51,15 @@ Features
* Tumblr API
* Twitter API
* Twilio API
- * Meetup API
+ * Meetup API
* Steam API
* Quandl Stock API
* New York Times API
* LinkedIn API
+ * Facebook API
+ * Google+ API
+ * Dropbox API
+ * Foursquare API
@@ -67,14 +77,14 @@ To get up and running, simply do the following:
$ git clone https://github.com/DrkSephy/django-hackathon-starter.git
$ cd django-hackathon-starter
-
+
# Install the requirements
$ pip install -r requirements.txt
-
+
# Install bower
$ npm install -g bower
$ bower install
-
+
# Perform database migrations
$ python manage.py makemigrations
$ python manage.py migrate
@@ -82,11 +92,8 @@ To get up and running, simply do the following:
**NOTE**: We highly recommend creating a [Virtual Environment](http://docs.python-guide.org/en/latest/dev/virtualenvs/). Python Virtual Environments allow developers to work in isolated sandboxes and to create separation between python packages installed via [pip](https://pypi.python.org/pypi/pip).
-**NOTE**: To get you up and running quickly, we have provided dummy API keys for use. We highly recommend setting up your own keys and replacing them within `settings.py`.
-
-
-
+
Getting API Keys
----------------
@@ -111,7 +118,7 @@ Getting API Keys
* For `redirect url` field, enter: `http://127.0.0.1:8000/hackathon/`
3. Within `settings.py`, add the following:
* `MEETUP_CONSUMER_KEY` = `Meetup key`
- * `MEETUP_CONSUMER_SECRET` = `Meetup secret key`
+ * `MEETUP_CONSUMER_SECRET` = `Meetup secret key`
@@ -119,7 +126,7 @@ Getting API Keys
1. Register an account on [Twilio.com](https://www.twilio.com/)
2. Get your [Twilio Number](https://www.twilio.com/user/account/phone-numbers/incoming)
-3. [Setup the numbers](https://www.twilio.com/user/account/phone-numbers/incoming) you want to be able to send messages to
+3. [Setup the numbers](https://www.twilio.com/user/account/phone-numbers/incoming) you want to be able to send messages to
4. Grab your `account_sid` and `auth_token` [here](https://www.twilio.com/user/account/voice-messaging)
5. Within `scripts/twilioapi.py`:
* Replace `account_sid` with your own Twilio `account_sid`
@@ -172,7 +179,6 @@ Getting API Keys
* `INSTAGRAM_CLIENT_ID` = `Instagram-client-id`
* `INSTAGRAM_CLIENT_SECRET` = `Instagram-client-secret`
-
@@ -193,17 +199,99 @@ Getting API Keys
1. Register an account on [Facebook.com](http://www.facebook.com.com/)
-2. Visit [Facebook Developer Network page](https://developers.facebook.com/)
-3. After logging in, Click on **My Apps** and then on **Add a New App+**
- * Choose Website as the platform and add the **name** for your project
- * Click on **Create New Facebook APP ID** and choose the **Category** of your application
+2. Visit [Facebook Developers page](https://developers.facebook.com/)
+3. After logging in, Click on **My Apps** and then on **Add a New App**
+ * Choose W**ebsite** as the platform and add the **name** for your project
+ * Give your app a name.
+ * Choose the category your app falls into.
* Click **Create App ID**
-4. After the captcha, scroll down past the quick start and add `http://localhost:8000/`
-5. Within your `views.py` add the **App ID** in `yourappid` underneath the view for your facebook application.
+ * Skip the quickstart process and you will be redirected to the app dashboard.
+4. Copy the **app ID** and the **app secret**.
+5. From the left menu choose the **Settings** option.
+6. Click on **Add Platform** and choose **Website** once again.
+7. Under **site URL**, specift the URL to be redirected after authentication is complete.
+8. Click save.
+9. In ```settings.py``` change the following values:
+ * ```FACEBOOK_APP_ID = your_app_id```
+ * ```FACEBOOK_APP_SECRET = your_app_secret```
+
+
+
+
+
+1. Register an account on [Google.com](https://accounts.google.com/signup).
+2. Navigate to [Google Developer Console](https://console.developers.google.com/project).
+3. Click on **Create Project**, give your app a name and click **Create** (this might take a few sceonds).
+4. You will be redirected to the project dashboard. From the left menu choose **APIs & auth** and then choose **APIs**.
+5. Choose the API you would like to use (the built in example uses **Google+ API**).
+6. Click on **Enable API**.
+7. From the side menu, under **APIs & auth** select **consent screen**.
+ * Fill your app name under **Product Name**.
+ * Hit **save** button on the bottom.
+8. From the side menu, under **APIs & auth** select credentials:
+ * Click on **Create new Client ID**.
+ * Under **Authorized JavaScript origins** specify you app base address (e.g ```http://localhost:8000```).
+ * Under **Authorized redirect URIs** specify the URL to be redirected after authentication is complete.
+ * Hit **Create Client ID** button (this might also take a few seconds).
+9. Copy your new generated ```client_id``` and ```client_secret```:
+10. Under ```settings.py``` change the following values:
+ * ```GOOGLE_PLUS_APP_ID = your_client_id```
+ * ```GOOGLE_PLUS_APP_SECRET = your_client_secret```
+
+
+1. Register an account on [Dropbox.com](http://www.dropbox.com).
+2. Navigate to [Dropbox Developers](https://www.dropbox.com/developers).
+3. From the side menu, select **App Console** and click on **Create app**.
+4. Configure the app permissions. This example uses the following configuration:
+ * App type- Dropbox API app
+ * My app needs access to files already on Dropbox.
+ * My app needs access to a user's full Dropbox.
+ * **Note:** This kind of configuration will require you to submit your app for approval.
+5. Give your app a name and click the **Create app button**.
+6. You will be redirected to the app console:
+ * Under **Redirect URIs** specify the URL to be redirected after authentication is complete (e.g ```http://locahost:8000/home```) and click **add**.
+ * Copy your ```App key``` and ```App secret```.
+7. Under ```settings.py``` change the following values:
+ * ```DROPBOX_APP_ID = your_app_id```
+ * ```DROPBOX_APP_SECRET = your_app_secret```
+
+
+
+
+1. Register and account on [Foursquare.com](https://foursquare.com).
+2. Navigate to [Foursquare For Developers](https://developer.foursquare.com).
+3. From the top menu bar select **My Apps** and you will be redirected to the app dashboard.
+4. Hit **Create a New App**:
+ * Give your app a name.
+ * Under **Download / welcome page url**, specify your app main url (e.g ```http://www.localhost:8000```).
+ * Under **Redirect URI**, specify the URL to be redirected after authentication is complete (e.g ```http://locahost:8000/home```) and click **add**.
+ * Scroll all the way to the botttom and hit **Save Changes**.
+5. From the App page you were redirected to, copy your ```App key``` and ```App secret```.
+6. Under ```settings.py``` change to following values:
+ * ```FOURSQUARE_APP_ID = your_client_id```
+ * ```FOURSQUARE_APP_SECRET = your_app_secret```
+
+
+
+
+
+1. Register an account on Tumblr.com.
+2. Visit Tumblr applications page.
+3. Click on Register Application.
+ * Enter your application information.
+ * For Default callback URL field, enter: http://127.0.0.1:8000/hackathon/.
+4. Click Register.
+5. Within settings.py, add the following:
+ * TUMBLR_CONSUMER_KEY = `Tumblr-consumer-key`
+ * TUMBLR_CONSUMER_SECRET = `Tumblr-consumer-secret`
+
+
+
+
1. Register an account on [Steam](https://store.steampowered.com/join/)
@@ -227,11 +315,11 @@ Getting API Keys
-
+
1. Register an account on [Quandl](https://www.quandl.com/)
-2. After logging in, click on **Me** and then **Account settings** to find the API key
-3. Within your `settings.py`add `QUANDLAPIKEY` = `Key`
+2. After logging in, click on **Me** and then **Account settings** to find the API key
+3. Within your `settings.py`add `QUANDLAPIKEY` = `Key`
@@ -241,37 +329,40 @@ Project Structure
| Name | Description |
| ---------------------------------- |:-----------------------------------------------------------:|
-| **hackathon_starter/hackathon_starter**/settings.py | Django settings module containing database and API keys/tokens.|
-| **hackathon_starter/hackathon**/admin.py | Registered models for Django's admin page.|
-| **hackathon_starter/hackathon**/models.py | Django models and profiles for user login.|
-| **hackathon_starter/hackathon**/tests.py | Integration tests.|
-| **hackathon_starter/hackathon**/urls.py | Django Hackathon Starter URL dispatcher.|
-| **hackathon_starter/hackathon**/views.py | Django views file.|
-| **hackathon_starter/hackathon**/serializers.py | Allows JSON representation for Django Model fields.|
-| **hackathon_starter/hackathon**/forms.py | Basic form fields.|
-| **hackathon_starter/hackathon/static/** | Front-end JavaScript / CSS files.|
-| **hackathon_starter/hackathon/unittests** | Unit tests.|
-| **hackathon_starter/hackathon/scripts/** | API Example scripts.|
-| **hackathon_starter/hackathon/scripts/**github.py | Script for interacting with Github API. |
-| **hackathon_starter/hackathon/scripts/**instagram.py| Script for interacting with Instagram API.|
-| **hackathon_starter/hackathon/scripts/**linkedin.py | Script for interacting with LinkedIn API. |
-| **hackathon_starter/hackathon/scripts/**meetup.py | Script for interacting with Meetup API. |
-| **hackathon_starter/hackathon/scripts/**nytimes.py | Script for interacting with New York Times API. |
-| **hackathon_starter/hackathon/scripts/**quandl.py | Script for interacting with Quandl API. |
-| **hackathon_starter/hackathon/scripts/**scraper.py | Basic web scraper for getting sales from Steam. |
-| **hackathon_starter/hackathon/scripts/**steam.py | Script for interacting with Steam API. |
-| **hackathon_starter/hackathon/scripts/**tumblr.py | Script for interacting with Tumblr API. |
-| **hackathon_starter/hackathon/scripts/**twilioapi.py | Script for interacting with Twilio API. |
-| **hackathon_starter/hackathon/scripts/**twitter.py | Script for interacting with Twitter API. |
-| **hackathon_starter/hackathon/scripts/**yelp.py | Script for interacting with Yelp API. |
-| **hackathon_starter/hackathon/templates/**hackathon/ | Templates for API examples. |
-| **hackathon_starter/hackathon/templates/**hackathon/base.html | Base template, contains navbar. |
-| **hackathon_starter/hackathon/templates/**hackathon/api_examples.html | Template for API Examples page. |
+| **hackathon_starter**/settings.py | Django settings module containing database and API keys/tokens|
+| **hackathon**/admin.py | Registered models for Django's admin page|
+| **hackathon**/models.py | Django models and profiles for user login|
+| **hackathon**/tests.py | Integration tests|
+| **hackathon**/urls.py | Django Hackathon Starter URL dispatcher|
+| **hackathon**/views.py | Django views file|
+| **hackathon**/serializers.py | Allows JSON representation for Django Model fields|
+| **hackathon**/forms.py | Basic form fields|
+| **hackathon/static/** | Front-end JavaScript / CSS files|
+| **hackathon/unittests** | Unit tests|
+| **hackathon/scripts/** | API Example scripts|
+| **hackathon/scripts/**github.py | Script for interacting with Github API |
+| **hackathon/scripts/**instagram.py| Script for interacting with Instagram API|
+| **hackathon/scripts/**linkedin.py | Script for interacting with LinkedIn API |
+| **hackathon/scripts/**meetup.py | Script for interacting with Meetup API |
+| **hackathon/scripts/**nytimes.py | Script for interacting with New York Times API |
+| **hackathon/scripts/**quandl.py | Script for interacting with Quandl API |
+| **hackathon/scripts/**scraper.py | Basic web scraper for getting sales from Steam |
+| **hackathon/scripts/**facebook.py | Script for interacting with Facebook API |
+| **hackathon/scripts/**dropbox.py | Script for interacting with Dropbox API |
+| **hackathon/scripts/**foursquare.py | Script for interacting with Foursquare API |
+| **hackathon/scripts/**googlePlus.py | Script for interacting with Google+ API |
+| **hackathon/scripts/**steam.py | Script for interacting with Steam API |
+| **hackathon/scripts/**tumblr.py | Script for interacting with Tumblr API |
+| **hackathon/scripts/**twilioapi.py | Script for interacting with Twilio API |
+| **hackathon/scripts/**twitter.py | Script for interacting with Twitter API |
+| **hackathon/scripts/**yelp.py | Script for interacting with Yelp API |
+| **hackathon/templates/**hackathon/ | Templates for API examples |
+| **hackathon/templates/**hackathon/base.html | Base template, contains navbar |
Contributing
------------
-We welcome contributions of all kinds. If you would like to know what work is needed to be done, check the [issue tracker](https://github.com/DrkSephy/django-hackathon-starter/issues). Before sending a pull request, please open an issue. This project follows the [pep-0008](https://www.python.org/dev/peps/pep-0008/) style guide.
+We welcome contributions of all kinds. If you would like to know what work is needed to be done, check the [issue tracker](https://github.com/DrkSephy/django-hackathon-starter/issues). Before sending a pull request, please open an issue. This project follows the [pep-0008](https://www.python.org/dev/peps/pep-0008/) style guide.
LICENSE
@@ -298,5 +389,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-
-
diff --git a/hackathon_starter/hackathon/admin.py b/hackathon_starter/hackathon/admin.py
index fce2802..c2c0a74 100644
--- a/hackathon_starter/hackathon/admin.py
+++ b/hackathon_starter/hackathon/admin.py
@@ -1,5 +1,5 @@
from django.contrib import admin
-from hackathon.models import UserProfile, Profile, InstagramProfile, TwitterProfile, MeetupToken, GithubProfile, LinkedinProfile
+from hackathon.models import UserProfile, Profile, InstagramProfile, TwitterProfile, MeetupToken, GithubProfile, LinkedinProfile, TumblrProfile
# Register your models here.
class TwitterProfileAdmin(admin.ModelAdmin):
@@ -12,4 +12,4 @@ class TwitterProfileAdmin(admin.ModelAdmin):
admin.site.register(GithubProfile)
admin.site.register(MeetupToken)
admin.site.register(LinkedinProfile)
-
+admin.site.register(TumblrProfile)
diff --git a/hackathon_starter/hackathon/models.py b/hackathon_starter/hackathon/models.py
index d9e098f..a5252d6 100644
--- a/hackathon_starter/hackathon/models.py
+++ b/hackathon_starter/hackathon/models.py
@@ -27,6 +27,15 @@ class GithubProfile(models.Model):
def __unicode__(self):
return unicode(self.user)
+class TumblrProfile(models.Model):
+ user = models.ForeignKey(User)
+ tumblr_user = models.CharField(max_length=200)
+ access_token = models.CharField(max_length=200)
+ access_token_secret = models.CharField(max_length=200)
+
+ def __unicode__(self):
+ return unicode(self.user)
+
class InstagramProfile(models.Model):
user = models.ForeignKey(User)
instagram_user = models.CharField(max_length=200)
@@ -66,4 +75,31 @@ class MeetupToken(models.Model):
access_token = models.CharField(max_length=200)
def __unicode__(self):
- return unicode(self.access_token)
\ No newline at end of file
+ return unicode(self.access_token)
+
+class FacebookProfile(models.Model):
+ user = models.ForeignKey(User)
+ fb_user_id = models.CharField(max_length=100)
+ time_created = models.DateTimeField(auto_now_add=True)
+ profile_url = models.CharField(max_length=50)
+ access_token = models.CharField(max_length=100)
+
+class GoogleProfile(models.Model):
+ user = models.ForeignKey(User)
+ google_user_id = models.CharField(max_length=100)
+ time_created = models.DateTimeField(auto_now_add=True)
+ access_token = models.CharField(max_length=100)
+ profile_url = models.CharField(max_length=100)
+
+class DropboxProfile(models.Model):
+ user = models.ForeignKey(User)
+ dropbox_user_id = models.CharField(max_length=100)
+ time_created = models.DateTimeField(auto_now_add=True)
+ access_token = models.CharField(max_length=100)
+
+
+class FoursquareProfile(models.Model):
+ user = models.ForeignKey(User)
+ foursquare_id = models.CharField(max_length=100)
+ time_created = models.DateTimeField(auto_now_add=True)
+ access_token = models.CharField(max_length=100)
diff --git a/hackathon_starter/hackathon/scripts/dropbox.py b/hackathon_starter/hackathon/scripts/dropbox.py
new file mode 100644
index 0000000..712e5f3
--- /dev/null
+++ b/hackathon_starter/hackathon/scripts/dropbox.py
@@ -0,0 +1,60 @@
+import simplejson as json
+import urllib
+import requests
+import string
+import pdb
+import random
+
+
+AUTHORIZE_URL = 'https://www.dropbox.com/1/oauth2/authorize'
+ACCESS_TOKEN_URL = 'https://api.dropbox.com/1/oauth2/token'
+
+
+class DropboxOauthClient(object):
+
+ access_token = None
+ session_id = None
+ def __init__(self, client_id, client_secret):
+ self.client_id = client_id
+ self.client_secret = client_secret
+
+
+ def get_authorize_url(self):
+ self.get_session_id()
+ authSettings = {'response_type': 'code',
+ 'client_id': self.client_id,
+ 'redirect_uri': 'http://localhost:8000/hackathon',
+ 'state': self.session_id}
+
+ params = urllib.urlencode(authSettings)
+
+ return AUTHORIZE_URL + '?' + params
+
+ def get_session_id(self, length=50):
+ chars = string.uppercase + string.digits + string.lowercase
+ self.session_id = ''.join(random.choice(chars) for _ in range(length))
+
+ def get_access_token(self, code, state):
+ if state != self.session_id:
+ raise(Exception('Danger! Someone is messing up with you connection!'))
+
+ authSettings = {'code': code,
+ 'grant_type': 'authorization_code',
+ 'client_id': self.client_id,
+ 'client_secret': self.client_secret,
+ 'redirect_uri': 'http://localhost:8000/hackathon'}
+
+ response = requests.post(ACCESS_TOKEN_URL, data=authSettings)
+
+ if response.status_code!=200:
+ raise(Exception('Invalid response, response code {c}'.format(c=response.status_code)))
+ self.access_token = response.json()['access_token']
+
+
+ def get_user_info(self):
+ USER_INFO_API = 'https://api.dropbox.com/1/account/info'
+ params = urllib.urlencode({'access_token': self.access_token})
+ response = requests.get(USER_INFO_API + '?' + params)
+ if response.status_code!=200:
+ raise(Exception('Invalid response, response code {c}'.format(c=response.status_code)))
+ return response.json()
diff --git a/hackathon_starter/hackathon/scripts/facebook.py b/hackathon_starter/hackathon/scripts/facebook.py
new file mode 100644
index 0000000..64018fd
--- /dev/null
+++ b/hackathon_starter/hackathon/scripts/facebook.py
@@ -0,0 +1,153 @@
+import requests
+import urllib
+import simplejson as json
+
+##########################
+# FACEBOOK API CONSTANTS #
+##########################
+
+AUTHORIZE_URL = 'https://graph.facebook.com/oauth/authorize'
+ACCESS_TOKEN_URL = 'https://graph.facebook.com/oauth/access_token'
+API_URL = 'https://graph.facebook.com/v2.3/'
+REQUEST_PERMISSIONS_URL = "https://www.facebook.com/dialog/oauth?"
+
+class FacebookOauthClient(object):
+ '''
+ Python client for Facebook API
+ '''
+
+ access_token = None
+ permission_request_url = None
+
+ def __init__(self, client_id, client_secret):
+ '''
+ Parameters:
+ client_id: String
+ - The client id from the registering app on Facebook
+ client_secret: String
+ - The client secret from the registering app on Facebook
+ '''
+ self.client_id = client_id
+ self.client_secret = client_secret
+
+
+
+ def get_authorize_url(self):
+ '''
+ Obtains authorize url link with given client_id.
+
+ Returns:
+ authURL: String
+ - The authorization url.
+
+ '''
+ authSettings = {'redirect_uri': "http://localhost:8000/hackathon/",
+ 'client_id': self.client_id}
+ params = urllib.urlencode(authSettings)
+ return AUTHORIZE_URL + '?' + params
+
+
+
+ def get_access_token(self, code):
+ '''
+ Obtains access token.
+
+ Parameters:
+ code: String
+ - The code is retrieved from the authorization url parameter
+ to obtain access_token.
+ '''
+ authSettings = {'code': code,
+ 'redirect_uri': "http://localhost:8000/hackathon/",
+ 'client_secret': self.client_secret,
+ 'client_id': self.client_id}
+ params = urllib.urlencode(authSettings)
+ response = requests.get(ACCESS_TOKEN_URL + '?' + params)
+
+ if response.status_code != 200:
+ raise(Exception('Invalid response,response code: {c}'.format(c=response.status_code)))
+
+ response_array = str(response.text).split('&')
+ self.access_token = str(response_array[0][13:])
+
+
+
+ def get_user_info(self):
+ '''
+ Obtains user information.
+
+ Returns:
+ content: Dictionary
+ - A dictionary containing user information.
+ '''
+ response = requests.get("https://graph.facebook.com/me?access_token={at}".format(at=self.access_token))
+ if response.status_code != 200:
+ raise(Exception('Invalid response,response code: {c}'.format(c=response.status_code)))
+
+ return response.json()
+
+
+
+
+ def get_user_likes(self):
+ '''
+ Obtains a list of all the user likes. Require a special permission
+ via Facebook.
+
+ Returns:
+ content: dictionary
+ -A dictionary containing user likes.
+ '''
+ #Check if permission exists or ask for it
+ if not self.check_permissions('user_likes'):
+ requestedPermissionUrl = self.request_permissions('user_likes')
+
+ #Get likes
+ response = requests.get(API_URL + 'me/likes?access_token={at}'.format(at=self.access_token))
+ return response.json()['data']
+
+
+
+ def check_permissions(self, perm):
+ '''
+ Checks if the app has the specified permission.
+
+ Parameters:
+ perm: String
+ - The desired permission (such as user_likes)
+
+ Returns:
+ bool
+ - True if the permission granted or false otherwise.
+ '''
+
+ permDict = {'status': 'granted', 'permission':perm}
+ response = requests.get(API_URL + 'me/permissions?access_token={at}'.format(at=self.access_token))
+ if response.status_code != 200:
+ raise(Exception('Invalid response,response code: {c}'.format(c=response.status_code)))
+
+ currentPermissions = response.json()['data']
+ if permDict in currentPermissions:
+ return True
+ return False
+
+
+ def request_permissions(self, perm):
+ '''
+ Requests a permission from the user.
+
+ Parameters:
+ perm: String
+ - The permission we would like to get.
+
+ Returns: String
+ - The URL to redirect the user in order to get the permission.
+ '''
+ authSettings = {'client_id' : self.client_id,
+ 'redirect_uri' : 'http://localhost:8000/hackathon/',
+ 'auth_type' : 'rerequest',
+ 'scope' : perm,
+ 'access_token' : access_token}
+ params = urllib.urlencode(authSettings)
+ self.permission_request_url = REQUEST_PERMISSIONS_URL + '?' + params
+
\ No newline at end of file
diff --git a/hackathon_starter/hackathon/scripts/foursquare.py b/hackathon_starter/hackathon/scripts/foursquare.py
new file mode 100644
index 0000000..a436b08
--- /dev/null
+++ b/hackathon_starter/hackathon/scripts/foursquare.py
@@ -0,0 +1,102 @@
+import simplejson as json
+import urllib
+import requests
+
+
+############################
+# FOURSQUARE API CONSTANTS #
+############################
+AUTHORIZE_URL = 'https://foursquare.com/oauth2/authenticate'
+ACCESS_TOKEN_URL = 'https://foursquare.com/oauth2/access_token'
+REDIRECT_URL = 'http://localhost:8000/hackathon'
+
+
+class FoursquareOauthClient(object):
+ '''
+ Pytohn client for Foursquare API
+ '''
+
+ access_token = None
+
+ def __init__(self, client_id, client_secret):
+ '''
+ Parameters:
+ client_id: String
+ - The client id from the registering app on Facebook
+ client_secret: String
+ - The client secret from the registering app on Facebook
+ '''
+ self.client_id = client_id
+ self.client_secret = client_secret
+
+
+
+ def get_authorize_url(self):
+ '''
+ Obtains authorize url link with given client_id.
+
+ Returns:
+ authURL: String
+ - The authorization url.
+
+ '''
+ authSettings = {'client_id': self.client_id,
+ 'response_type': 'code',
+ 'redirect_uri': REDIRECT_URL}
+
+ params = urllib.urlencode(authSettings)
+
+ return AUTHORIZE_URL + '?' + params
+
+
+
+ def get_access_token(self, code):
+ '''
+ Obtains access token.
+
+ Parameters:
+ code: String
+ - The code is retrieved from the authorization url parameter
+ to obtain access_token.
+ '''
+
+ authSettings = {'client_id': self.client_id,
+ 'client_secret': self.client_secret,
+ 'grant_type': 'authorization_code',
+ 'redirect_uri': REDIRECT_URL,
+ 'code': code}
+
+ params = urllib.urlencode(authSettings)
+ response = requests.get(ACCESS_TOKEN_URL + '?' + params)
+
+ if response.status_code != 200:
+ raise(Exception('Invalid response,response code: {c}'.format(c=response.status_code)))
+
+ self.access_token = response.json()['access_token']
+
+
+ def get_user_info(self, api_version='20140806'):
+ '''
+ Obtains user information.
+
+ Parameters:
+ api_version: string
+ - The API version you would use. This parameter is mandatory by Foursquare.
+
+ Returns:
+ content: Dictionary
+ - A dictionary containing user information.
+ '''
+ USER_INFO_API_URL = 'https://api.foursquare.com/v2/users/self'
+
+ authSettings={'v':api_version,
+ 'oauth_token': self.access_token}
+
+ params = urllib.urlencode(authSettings)
+
+ response = requests.get(USER_INFO_API_URL + '?' + params)
+
+ if response.status_code != 200:
+ raise(Exception('Invalid response,response code: {c}'.format(c=response.status_code)))
+
+ return response.json()['response']['user']
diff --git a/hackathon_starter/hackathon/scripts/googlePlus.py b/hackathon_starter/hackathon/scripts/googlePlus.py
new file mode 100644
index 0000000..573dfb6
--- /dev/null
+++ b/hackathon_starter/hackathon/scripts/googlePlus.py
@@ -0,0 +1,109 @@
+import requests
+import urllib
+import simplejson as json
+import random
+import string
+
+
+AUTHORISE_URL = 'https://accounts.google.com/o/oauth2/auth'
+ACCESS_TOKEN_URL = 'https://accounts.google.com/o/oauth2/token'
+REDIRECT_URL = 'http://localhost:8000/hackathon/'
+PROFILE_API = 'https://www.googleapis.com/auth/plus.login'
+
+class GooglePlus:
+
+ access_token = None
+ session_id = None
+
+ def __init__(self, client_id, client_secret):
+ '''
+ Parameters:
+ client_id: string
+ - The client ID from the registering app on Google.
+
+ client_secret: string
+ -The client secret from the registering app on Google.
+ '''
+ self.client_id = client_id
+ self.client_secret = client_secret
+
+
+ def get_session_id(self, length=50):
+ '''
+ Generates a random session ID. As a part from the authentication process
+ we need to verify that the response we get from the server contains the
+ same session ID as we sent.
+
+ Parameters:
+ length: integer
+ - The length of the session ID.
+ '''
+ chars = string.uppercase + string.digits + string.lowercase
+ self.session_id = ''.join(random.choice(chars) for _ in range(length))
+
+
+ def get_authorize_url(self):
+ '''
+ Obtains authorize url link with the given client_id.
+
+ Returns:
+ authURL: string
+ - The authorization URL.
+ '''
+
+ self.get_session_id()
+ authSettings = {'state': self.session_id,
+ 'redirect_uri':REDIRECT_URL,
+ 'response_type':'code',
+ 'client_id':self.client_id,
+ 'scope': PROFILE_API}
+
+ params = urllib.urlencode(authSettings)
+ return AUTHORISE_URL + '?' + params
+
+
+ def get_access_token(self, code, state):
+ '''
+ Obtains access token.
+
+ Parameters:
+ code: string
+ - The code is retrived from the authorization URL parameter
+ to obtain access token.
+ state: string
+ - The unique session ID.
+ '''
+
+ #Checking that the sessino ID from the response match the session ID we sent
+ if state != self.session_id:
+ raise(Exception('Danger! Someone is messing up with you connection!'))
+
+ authSettings = {'client_secret': self.client_secret,
+ 'code':code,
+ 'grant_type':'authorization_code',
+ 'client_id': self.client_id,
+ 'redirect_uri': 'http://localhost:8000/hackathon/'}
+
+ response = requests.post(ACCESS_TOKEN_URL, data=authSettings)
+ if response.status_code != 200:
+ raise(Exception('Invalid response, response code {c}'.format(c=response.status_code)))
+
+ self.access_token = response.json()['access_token']
+
+
+
+ def get_user_info(self):
+ '''
+ Obtain user information.
+
+ Returns:
+ content: dictionary
+ - A dictionary contains user information.
+ '''
+ USER_INFO_API = 'https://www.googleapis.com/oauth2/v2/userinfo'
+ params = urllib.urlencode({'access_token' : self.access_token})
+ response = requests.get(USER_INFO_API + '?' + params)
+ if response.status_code != 200:
+ raise(Exception('Invalid response, response code {c}'.format(c=response.status_code)))
+
+ return response.json()
\ No newline at end of file
diff --git a/hackathon_starter/hackathon/scripts/linkedin.py b/hackathon_starter/hackathon/scripts/linkedin.py
index 6667478..5a4d444 100644
--- a/hackathon_starter/hackathon/scripts/linkedin.py
+++ b/hackathon_starter/hackathon/scripts/linkedin.py
@@ -21,7 +21,7 @@ def get_authorize_url(self):
'client_secret' : self.client_secret,
'redirect_uri' : 'http://127.0.0.1:8000/hackathon/',
'state' : 'DCEeFWf45A53sdfKef424',
- 'scope': 'r_fullprofile'}
+ 'scope': 'r_basicprofile'}
params = urllib.urlencode(auth_setting)
authURL = AUTHORIZATION_URL + '?' + params
diff --git a/hackathon_starter/hackathon/scripts/tumblr.py b/hackathon_starter/hackathon/scripts/tumblr.py
index 3d0c188..dec46d6 100644
--- a/hackathon_starter/hackathon/scripts/tumblr.py
+++ b/hackathon_starter/hackathon/scripts/tumblr.py
@@ -32,7 +32,8 @@ class TumblrOauthClient(object):
oauth_verifier = None
oauth_token = None
oauth_token_secret = None
- accessed = False
+ is_authorized = False
+ access_token = None
def __init__(self, consumer_key, consumer_secret):
self.consumer_key = consumer_key
@@ -59,16 +60,16 @@ def access_token_url(self, oauth_verifier=''):
'''
Returns an access token to the user.
'''
- self.accessed = True
+ self.is_authorized = True
token = oauth2.Token(self.oauth_token, self.oauth_token_secret)
self.oauth_verifier = oauth_verifier
print self.oauth_verifier
token.set_verifier(self.oauth_verifier)
client = oauth2.Client(self.consumer, token)
resp, content = client.request(access_token_url, "POST")
- access_token = dict(urlparse.parse_qsl(content))
+ self.access_token = dict(urlparse.parse_qsl(content))
#set verified token
- self.token = oauth2.Token(access_token['oauth_token'], access_token['oauth_token_secret'])
+ self.token = oauth2.Token(self.access_token['oauth_token'], self.access_token['oauth_token_secret'])
def getUserInfo(self):
''' Returns users information. '''
@@ -81,6 +82,7 @@ def getUserInfo(self):
#return content in json format
jsonlist = json.loads(content)
response = jsonlist['response']
+ self.username = str(response['user']['name'])
user_info = response['user']
total_blogs = len(user_info['blogs'])
#print user_info
diff --git a/hackathon_starter/hackathon/templates/hackathon/api_examples.html b/hackathon_starter/hackathon/templates/hackathon/api_examples.html
index dd9dc76..3ddc3e1 100644
--- a/hackathon_starter/hackathon/templates/hackathon/api_examples.html
+++ b/hackathon_starter/hackathon/templates/hackathon/api_examples.html
@@ -4,22 +4,26 @@