Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.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
在显示twitter提要时,如何检查特定tweet是否使用JavaScript或JQuery转发?_Javascript_Jquery_Twitter_Social Media - Fatal编程技术网

在显示twitter提要时,如何检查特定tweet是否使用JavaScript或JQuery转发?

在显示twitter提要时,如何检查特定tweet是否使用JavaScript或JQuery转发?,javascript,jquery,twitter,social-media,Javascript,Jquery,Twitter,Social Media,可能重复: 所以我一直在写一个推特提要脚本,这个脚本可以拉入我的提要。我想知道我该如何检查一条特定的推文是否被转发,然后如果它被转发,我想使用转发推文中的信息。下面是twitter API为转发生成的关联数组示例 Array ( [0] => Array ( [created_at] => Sun Jan 06 08:28:39 +0000 2013 [id] => 287838076443705345

可能重复:

所以我一直在写一个推特提要脚本,这个脚本可以拉入我的提要。我想知道我该如何检查一条特定的推文是否被转发,然后如果它被转发,我想使用转发推文中的信息。下面是twitter API为转发生成的关联数组示例

Array
(
    [0] => Array
        (
            [created_at] => Sun Jan 06 08:28:39 +0000 2013
            [id] => 287838076443705345
            [id_str] => 287838076443705345
            [text] => RT @Fullscreen: Heads-up: many YT partners are reporting issues claiming their videos. It appears to be a YT bug. We will keep you posted.
            [source] => web
            ... 
            [user] => Array
                (
                    [id] => 212642904
                    [id_str] => 212642904
                    [name] => Elias Ranz-Schleifer
                    [screen_name] => Xxplosions
                    ... 
                )
                ...
            [retweeted_status] => Array
                (
                    [created_at] => Sun Jan 06 02:08:43 +0000 2013
                    [id] => 287742460824805378
                    [id_str] => 287742460824805378
                    [text] => Heads-up: many YT partners are reporting issues claiming their videos. It appears to be a YT bug. We will keep you posted.
                    ... 
                    [user] => Array
                        (
                            [id] => 238110322
                            [id_str] => 238110322
                            [name] => Fullscreen, Inc.
                            [screen_name] => Fullscreen
                            ... 
                        )
                        ...
                )

            [retweet_count] => 44
            ...
        )

)
所以本质上我想用
[text]=>Heads-up:many…
替换
[text]=>RT@Fullscreen:Heads-up:many…
,只要它存在。如果它不存在,那么使用从tweet中提取信息的常规方法。我想基本上我想了解的是如何检查
[retweetd\u status]
是否存在,然后提取该信息,如果不存在,则提取其他信息。我希望避免将RT放在那里,因为它似乎是可能的,并且使用诸如
id\u str、文本、屏幕名称等信息。

我用来获取常规推文信息的代码是:

id = tweets[i]["id_str"];
twitPic = tweets[0]["user"]["profile_image_url_https"];
content = tweets[i]["text"];
tweetTime = tweets[i]["created_at"];

其中,
i
被for循环中的索引替换。如果您对我想要了解的内容有任何疑问,请告诉我,我很乐意澄清。

您可以测试密钥是否存在,如下所示:

// save current tweet
var tweet = tweets[i];
var id = tweet.id_str;
var twitPic = tweet.user.profile_image_url_https;
var tweetTime = tweet.created_at;
var isRetweet = Object.prototype.toString.call(tweet.retweeted_status).slice(8, -1) === 'Object';
// try to use text from original tweet
var content = isRetweet ? tweet.retweeted_status.text : tweet.text;
// by using the 'in' operator
content = ('retweeted_status' in tweets[i]) ?  tweets[i]["retweeted_status"] : tweets[i]["text"];
// or by using the method 'hasOwnProperty()'
if(tweets[i].hasOwnProperty('retweeted_status')) {
    content = tweets[i]["retweeted_status"];
} else {
    content = tweets[i]["text"];
}

您也可以检查未定义,但这不是测试键是否存在的准确方法(如果键存在但值实际上未定义怎么办?)

您可以测试密钥是否存在,如下所示:

// by using the 'in' operator
content = ('retweeted_status' in tweets[i]) ?  tweets[i]["retweeted_status"] : tweets[i]["text"];
// or by using the method 'hasOwnProperty()'
if(tweets[i].hasOwnProperty('retweeted_status')) {
    content = tweets[i]["retweeted_status"];
} else {
    content = tweets[i]["text"];
}
您也可以检查未定义,但这不是测试键是否存在的准确方法(如果键存在但值实际上未定义怎么办?)