gpt4 book ai didi

javascript - 如何在 Twitter API 响应中检索 [object Object] 值

转载 作者:行者123 更新时间:2023-11-30 00:32:58 25 4
gpt4 key购买 nike

我目前正在使用 twitter API(twit npm 包),我目前正在收到结构如下的响应

{ metadata: [Object],                                                                                                                                                                         
I20150213-22:24:29.155(0)? created_at: 'Fri Feb 13 22:24:07 +0000 2015',
I20150213-22:24:29.156(0)? id: 566362206468845600,
I20150213-22:24:29.156(0)? id_str: '566362206468845569',
I20150213-22:24:29.157(0)? text: 'Photo: New BTS picture from Mockingjay part http://t.co/fo30mcLRYV',
I20150213-22:24:29.158(0)? source: '<a href="http://www.tumblr.com/" rel="nofollow">Tumblr</a>',
I20150213-22:24:29.158(0)? truncated: false,
I20150213-22:24:29.159(0)? in_reply_to_status_id: null,
I20150213-22:24:29.159(0)? in_reply_to_status_id_str: null,
I20150213-22:24:29.160(0)? in_reply_to_user_id: null,
I20150213-22:24:29.160(0)? in_reply_to_user_id_str: null,
I20150213-22:24:29.161(0)? in_reply_to_screen_name: null,
I20150213-22:24:29.161(0)? user: [Object],
I20150213-22:24:29.162(0)? geo: null,
I20150213-22:24:29.162(0)? coordinates: null,
I20150213-22:24:29.163(0)? place: null,
I20150213-22:24:29.163(0)? contributors: null,
I20150213-22:24:29.164(0)? retweet_count: 0,
I20150213-22:24:29.288(0)? favorite_count: 0,
I20150213-22:24:29.289(0)? entities: [Object],
I20150213-22:24:29.289(0)? favorited: false,
I20150213-22:24:29.290(0)? retweeted: false,
I20150213-22:24:29.290(0)? possibly_sensitive: false,
I20150213-22:24:29.291(0)? lang: 'en' },

我正在尝试检索实体对象以访问其中的潜在媒体项,但是当我使用 console.log() 时,此数组 [object Object] 中的实体键被记录。如何访问对象的内部?我打算从此对象中提取图片 url,但看不到里面的内容。根据 Twitter API 网站,媒体存储在实体对象中。

如有任何帮助,我们将不胜感激。

最佳答案

图像的 URL 存储在 REST 调用返回的 JSON 响应中的实体 media 中。

假设您要访问 media_url 实体,只需按如下方式访问即可

var result = the result from your call...
var imageUrl = result.entities.media.media_url;

并以您想要的任何方式使用媒体 URL。

如果您想检查媒体内容是否存在,只需使用if(result.entities.media.length > 0)

关于javascript - 如何在 Twitter API 响应中检索 [object Object] 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28509919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com