Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.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用户信息时,它';s仅返回用户名_Python_Instagram_Instagram Api - Fatal编程技术网

Python 当我请求instagram用户信息时,它';s仅返回用户名

Python 当我请求instagram用户信息时,它';s仅返回用户名,python,instagram,instagram-api,Python,Instagram,Instagram Api,我使用这个python: 我没有收到这个答案: { "data": { "id": "1574083", "username": "snoopdogg", "full_name": "Snoop Dogg", "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg",

我使用这个python:

我没有收到这个答案:

{
    "data": {
        "id": "1574083",
        "username": "snoopdogg",
        "full_name": "Snoop Dogg",
        "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg",
        "bio": "This is my bio",
        "website": "http://snoopdogg.com",
        "counts": {
            "media": 1320,
            "follows": 420,
            "followed_by": 3410
        }
}

我怎么能检索个人简历、粉丝数等信息?谢谢

您实际上收到了整个响应,但是Python版本的Instagram API客户端正在返回其
用户
类的实例(继承自
ApiModel
类)

通过单独访问这些属性,您可以获得所需的所有数据:

user = api.user('1574083')
print user.username
print user.full_name
print user.profile_picture
print user.bio
print user.website
print user.counts 
其中打印:

snoopdogg
snoopdogg
http://scontent.cdninstagram.com/hphotos-xap1/t51.2885-19/11186934_976841435684008_1692889037_a.jpg
Get BUSH now!
http://smarturl.it/BushAlbum
{u'media': 19019, u'followed_by': 6746636, u'follows': 1707}
这是有欺骗性的,因为如果你只打印
用户
,你只会看到
用户:Snoopdog
。在Python中,可以覆盖许多其他语言不允许的方法。特别是在这里,它们覆盖了
\uuuu str\uuuuu
\uuu repr\uuuu
\uuuuu unicode\uuuuu
,它们都用于将对象转换为字符串类型的对象进行打印


我的理解是,
\uuuuu str\uuuuu
\uuuuu unicode\uuuuu
应该是“漂亮”的版本,而
\uuuu repr\uuuu
应该向您展示(如果可能的话)如何重建对象。他们在实现这两个目标方面做得很差,但可以说这比对象的默认表示要好,默认表示类似于

,那么,您到底收到了什么?如果可能,使用HTTP状态代码。如何查看可访问的属性列表?在Python中,有一个内置函数,
dir
,它返回参数()的有效属性列表。在这种情况下,如果我运行
print dir(user)
我会得到一个列表,其中包括字段“bio”、“counts”、“full\u name”、“id”、“object\u from\u dictionary”、“profile\u picture”、“username”、“website”(以及一系列内置函数,如
\uu str\uuuuuuuu
\uu dict\uuu
)。
snoopdogg
snoopdogg
http://scontent.cdninstagram.com/hphotos-xap1/t51.2885-19/11186934_976841435684008_1692889037_a.jpg
Get BUSH now!
http://smarturl.it/BushAlbum
{u'media': 19019, u'followed_by': 6746636, u'follows': 1707}