Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit c7656b7

Browse files
committed
updated sample to use new media methods
1 parent c8f47b9 commit c7656b7

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

instagram/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class ApiModel(object):
66
@classmethod
77
def object_from_dictionary(cls, entry):
88
# make dict keys all strings
9+
if entry is None:
10+
return ""
911
entry_str_dict = dict([(str(key), value) for key, value in entry.items()])
1012
return cls(**entry_str_dict)
1113

sample_app.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ def on_recent(session):
7474
photos = []
7575
for media in recent_media:
7676
if(media.type == 'video'):
77-
photos.append('<video controls width height="150"><source type="video/mp4" src="%s"/></video>' % (media.videos['low_resolution'].url))
77+
photos.append('<video controls width height="150"><source type="video/mp4" src="%s"/></video>' % (media.get_standard_resolution_url()))
7878
else:
79-
photos.append('<img src="%s"/>' % (media.images['thumbnail'].url))
79+
photos.append('<img src="%s"/>' % (media.get_low_resolution_url()))
8080
content += ''.join(photos)
8181
except Exception, e:
8282
print e
@@ -93,12 +93,12 @@ def on_user_media_feed(session):
9393
media_feed, next = api.user_media_feed()
9494
photos = []
9595
for media in media_feed:
96-
photos.append('<img src="%s"/>' % media.images['thumbnail'].url)
96+
photos.append('<img src="%s"/>' % media.get_standard_resolution_url())
9797
counter = 1
9898
while next and counter < 3:
9999
media_feed, next = api.user_media_feed(with_next_url=next)
100100
for media in media_feed:
101-
photos.append('<img src="%s"/>' % media.images['thumbnail'].url)
101+
photos.append('<img src="%s"/>' % media.get_standard_resolution_url())
102102
counter += 1
103103
content += ''.join(photos)
104104
except Exception, e:
@@ -116,7 +116,7 @@ def location_recent_media(session):
116116
recent_media, next = api.location_recent_media(location_id=514276)
117117
photos = []
118118
for media in recent_media:
119-
photos.append('<img src="%s"/>' % media.images['thumbnail'].url)
119+
photos.append('<img src="%s"/>' % media.get_standard_resolution_url())
120120
content += ''.join(photos)
121121
except Exception, e:
122122
print e
@@ -133,7 +133,7 @@ def media_search(session):
133133
media_search = api.media_search(lat="37.7808851",lng="-122.3948632",distance=1000)
134134
photos = []
135135
for media in media_search:
136-
photos.append('<img src="%s"/>' % media.images['thumbnail'].url)
136+
photos.append('<img src="%s"/>' % media.get_standard_resolution_url())
137137
content += ''.join(photos)
138138
except Exception, e:
139139
print e
@@ -150,7 +150,7 @@ def media_popular(session):
150150
media_search = api.media_popular()
151151
photos = []
152152
for media in media_search:
153-
photos.append('<img src="%s"/>' % media.images['thumbnail'].url)
153+
photos.append('<img src="%s"/>' % media.get_standard_resolution_url())
154154
content += ''.join(photos)
155155
except Exception, e:
156156
print e
@@ -202,7 +202,7 @@ def tag_search(session):
202202
tag_recent_media, next = api.tag_recent_media(tag_name=tag_search[0].name)
203203
photos = []
204204
for tag_media in tag_recent_media:
205-
photos.append('<img src="%s"/>' % tag_media.images['thumbnail'].url)
205+
photos.append('<img src="%s"/>' % tag_media.get_standard_resolution_url())
206206
content += ''.join(photos)
207207
except Exception, e:
208208
print e

0 commit comments

Comments
 (0)