简体   繁体   English

使用Instagram Python API获取媒体

[英]Get media with Instagram Python API

I want to be able to list out the URLs of recent media items from an authorized account. 我希望能够列出来自授权帐户的最新媒体项目的URL。 This is the first time I've ever tried using the Python-Instagram API. 这是我第一次尝试使用Python-Instagram API。 I have all sensitive variables filled out in the following snippet. 我在以下代码段中填写了所有敏感变量。

from instagram.client import InstagramAPI
from urllib.request import urlopen
import json

access_token = ""
client_secret = ""
api = InstagramAPI(access_token=access_token, client_secret=client_secret)

user_id = ""

def get_media():
    request = 'https://api.instagram.com/v1/users/{USERID}/media/recent/?access_token={ACCESS_TOKEN}'
    response = urlopen(request).read().decode('utf8')
    obj = json.loads(response)

    for i in obj['data']['link']:
        print (i['link'])

This returns absolutely nothing. 这绝对不会返回任何内容。

print (obj) returns the json in plain text. print (obj)以纯文本形式返回json。 (is this the proper way of doing things? Or are there calls in the API that do this like api.get_recent_media() ? (这是正确的处理方式吗?还是API中有像api.get_recent_media()这样的api.get_recent_media()

The API provides a user_recent_media method. 该API提供了user_recent_media方法。 This is the example given in the docs on how to use it: 这是文档中给出的有关如何使用它的示例:

recent_media, next_ = api.user_recent_media()
photos = []
for media in recent_media:
    photos.append('<img src="%s"/>' % media.images['thumbnail'].url)

The format of the response can be gleaned from the endpoint documentation . 响应的格式可以从端点文档中收集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM