looking at the documentation
api.user_recent_media(userid='1034466',count=1)
returns
([], None)
What to do?
p.s. btw get userid from http://jelled.com/instagram/lookup-user-id
Basically you should user_id
instead of userid
.
However I might help you go a little further with what you're trying to do, since I've done the same thing (retrieve instagram media from a user) some weeks ago:
Definition:
class InstagramFeed:
api = InstagramAPI(client_id=settings.SOCIAL_AUTH_INSTAGRAM_KEY,
client_secret=settings.SOCIAL_AUTH_INSTAGRAM_SECRET)
logger = logging.getLogger(__name__)
def get_user_id(self, user_name):
users = self.api.user_search(q=user_name)
for user in users:
if user_name == user.username:
return user.id
else:
self.logger.error('Instagram User with username {0} NOT FOUND!', user_name)
raise Exception('Instagram User with username {0} NOT FOUND!', user_name)
@classmethod
def get_media(cls, user_name, count=8):
user_id = cls.get_user_id(cls, user_name)
if user_id is None:
return None
recent_media, next_ = cls.api.user_recent_media(user_id=user_id, count=count)
return recent_media
class InstagramEncoder(json.JSONEncoder):
def default(self, o):
if type(o) in (instagram.models.Comment, instagram.models.Image,
instagram.models.Location, instagram.models.Media,
instagram.models.MediaShortcode, instagram.models.Point,
instagram.models.Relationship, instagram.models.Tag,
instagram.models.User, instagram.models.Video, instagram.models.UserInPhoto,
instagram.models.Position):
return o.__dict__
elif isinstance(o, datetime.datetime):
unix_time = time.mktime(o.timetuple())
return str(unix_time)
else:
return default(o)
usage:
media = InstagramFeed.get_media(user_name=user_name, count=8)
imports (I'm using it within a django1.8 project):
from instagram.client import InstagramAPI
from django.conf import settings
from bson.json_util import default
import json
import logging
import instagram.models
import time
import datetime