PHP Twitter API“获取用户/查找".从 id 中获取 screen_name [英] PHP Twitter API "GET users/lookup". Grabbing screen_name from id

查看:31
本文介绍了PHP Twitter API“获取用户/查找".从 id 中获取 screen_name的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个简单的 Twitter API 程序,该程序将遍历您的关注者并获取所有关注者.它通过他们的 ID 获取他们.我如何获得他们的 screen_name?

我知道我必须用 user_id 作为参数之一对用户/查找做一些事情.

我注意到我认为是我的问题.

我尝试使用的 JSON 代码是这样的.

<预><代码>[{屏幕名称":推特"}]

我已经这样做了(如下)

<代码>{屏幕名称":推特"}

使用查找功能(https://dev.twitter.com/docs/api/1/get/users/lookup) 以["开头.

我想我必须做类似的事情.

$LookUp_JSON->[1]->screen_name然后会打印twitter",但显然不是.

解决方案

查看 Twitter API 控制台 ( https://dev.twitter.com/console )

.. 稍微修改一下,因为从控制台的角度来看它没有记录.

转到users/show,你会看到这个

http://api.twitter.com/1/users/show.json?screen_name={screen_name}

改成这个

http://api.twitter.com/1/users/show.json?user_id={id}

I.E 为@TwitterAPI (6253282) 此调用的 ID

http://api.twitter.com/1/users/show.json?user_id=6253282

会给你这个:

<代码>{身份证":6253282,"id_str": "6253282","name": "Twitter API","screen_name": "twitterapi","location": "加利福尼亚州旧金山",等等...}

I have made a simple Twitter API program that will loop through your Followers and grab all of them. It gets them by their IDs. How do I get their screen_name?

I know I have to do something with users/lookup with user_id as one of the parameters.

I have noticed what I think is my issue.

The JSON code that I am trying to get to goes something like this.

[
 {
  "screen_name": "twitter"
 }
]

I have done it like (below.)

{
  "screen_name": "twitter"
}

With the Lookup Function (https://dev.twitter.com/docs/api/1/get/users/lookup) it starts with the "[".

I was thinking I would have to do something like.

$LookUp_JSON->[1]->screen_name which would then print "twitter" but it's obviously not.

解决方案

Check out the Twitter API console ( https://dev.twitter.com/console )

.. and hack it a little bit because its undocumented from the console standpoint.

Go to users/show where you'll see this

http://api.twitter.com/1/users/show.json?screen_name={screen_name}

change it to this

http://api.twitter.com/1/users/show.json?user_id={id}

I.E for the ID of @TwitterAPI (6253282) this call

http://api.twitter.com/1/users/show.json?user_id=6253282

will get you this:

{
  "id": 6253282,
  "id_str": "6253282",
  "name": "Twitter API",
  "screen_name": "twitterapi",
  "location": "San Francisco, CA",
etc...
}

这篇关于PHP Twitter API“获取用户/查找".从 id 中获取 screen_name的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆