forked from DrkSephy/django-hackathon-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in mk200789/django-hackathon-starter (pull request DrkSephy#21)
instagram template + views + script
- Loading branch information
Showing
8 changed files
with
159 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import requests | ||
import urllib | ||
import urllib2 | ||
import json | ||
import simplejson as json2 | ||
|
||
authorization_url = 'https://api.instagram.com/oauth/authorize/?client_id=' | ||
access_token_url = 'https://api.instagram.com/oauth/access_token' | ||
|
||
class InstagramOauthClient(object): | ||
|
||
access_token = None | ||
user_data = None | ||
|
||
def __init__(self, client_id, client_secret): | ||
self.client_id = client_id | ||
self.client_secret = client_secret | ||
|
||
def get_authorize_url(self): | ||
''' Obtains the authorization url. ''' | ||
auth_url = authorization_url + self.client_id +'&redirect_uri=http://localhost:8000/hackathon/instagram&response_type=code' | ||
return auth_url | ||
|
||
def get_access_token(self, code): | ||
''' Obtains access token. ''' | ||
|
||
auth_setting = {'client_id': self.client_id, | ||
'client_secret': self.client_secret, | ||
'grant_type': 'authorization_code', | ||
'redirect_uri': 'http://localhost:8000/hackathon/instagram', | ||
'code': code | ||
} | ||
|
||
auth_setting_url = urllib.urlencode(auth_setting) | ||
req = urllib2.Request(access_token_url, auth_setting_url) | ||
content = urllib2.urlopen(req) | ||
jsonlist = json.load(content) | ||
self.access_token = jsonlist['access_token'] | ||
self.user_data = jsonlist['user'] | ||
print self.access_token | ||
|
||
|
||
def get_tagged_media(self, tag): | ||
''' Get recent tagged media. ''' | ||
tagged_media_url = 'https://api.instagram.com/v1/tags/'+tag+'/media/recent?access_token='+self.access_token# +'&count=2' | ||
req = requests.get(tagged_media_url) | ||
content = json2.loads(req.content) | ||
data = content['data'] | ||
|
||
while len(data) <= 100: | ||
next_url= content['pagination']['next_url'] | ||
req = requests.get(next_url) | ||
content = json2.loads(req.content) | ||
for i in content['data']: | ||
data.append(i) | ||
print len(data) | ||
return data | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
hackathon_starter/hackathon/templates/hackathon/instagram.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
{% include 'hackathon/base.html' %} | ||
<h1 class="text-center"> {{ title }}</h1> | ||
<br> | ||
<div class="col-lg-12"> | ||
<div class="table-responsive"> | ||
<h2> #{{search_tag}} </h2> | ||
<table class="table"> | ||
{% for i in tagged_media %} | ||
<img src="{{i.images.thumbnail.url}}"> | ||
{% endfor %} | ||
</table> | ||
</div> | ||
</div> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters