Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python instagram api用户\最近\媒体返回无_Python_Instagram_Instagram Api - Fatal编程技术网

python instagram api用户\最近\媒体返回无

python instagram api用户\最近\媒体返回无,python,instagram,instagram-api,Python,Instagram,Instagram Api,看着 返回 ([], None) 怎么办 p、 顺便说一句,从中获取用户id请尝试用户id='1034466'而不是用户id='1034466'基本上您应该用户id而不是用户id 不过,我可能会帮助您进一步了解您正在尝试做的事情,因为几周前我也做了同样的事情(从用户那里检索instagram媒体): 定义: class InstagramFeed: api = InstagramAPI(client_id=settings.SOCIAL_AUTH_INSTAGRAM_KEY,

看着

返回

([], None)
怎么办


p、 顺便说一句,从中获取用户id请尝试用户id='1034466'而不是用户id='1034466'

基本上您应该
用户id
而不是
用户id

不过,我可能会帮助您进一步了解您正在尝试做的事情,因为几周前我也做了同样的事情(从用户那里检索instagram媒体):

定义:

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)
用法:

media = InstagramFeed.get_media(user_name=user_name, count=8)
导入(我在django1.8项目中使用它):


我浪费了1个小时来思考这个问题。谢谢,哈哈,你可以看到我在下面回答了我自己的问题,因为这更像是一个问答问题。你仍然可以投票。干杯您正在使用的cls是什么?对不起,我不确定我是否理解您的问题,请解释一下好吗?更新:Instagram在过去几个月更改了API,所以我不确定这个解决方案是否有效。
media = InstagramFeed.get_media(user_name=user_name, count=8)
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