【问题标题】:How to grab the username in the JSON Twitter V2 response using PHP?如何使用 PHP 在 JSON Twitter V2 响应中获取用户名?
【发布时间】:2021-07-20 03:36:29
【问题描述】:

例如,我可以使用下面的代码获取“文本”,但如何在包含 > 用户下获取用户名“Lionek_Gaming”?

$tweets = json_decode($response);

foreach($tweets->data as $tweet) {

$text = $tweet->text;

echo $text;

}

Json 响应

{
    "data": [
        {
            "author_id": "1169144412171055104",
            "id": "1386731275160072192",
            "text": "sell Bitcoin at sweet rates"
        }
 
    ],
    "includes": {
        "users": [

            {
                "id": "1304731585112158209",
                "name": "Lionek_official #BRG",
                "username": "Lionek_Gaming"
            }
        ]
    },

}

【问题讨论】:

  • 可能使用authorId查询姓名

标签: php json twitter


【解决方案1】:

尝试以下方法:

foreach($tweets->includes->users as $user) {
    $username = $user->username;
    echo $username;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-02
    • 2013-04-20
    • 2019-10-24
    • 1970-01-01
    • 1970-01-01
    • 2018-03-07
    • 1970-01-01
    相关资源
    最近更新 更多