Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.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
Javascript 从嵌入的twitter时间线解析推特内容_Javascript_Php_Twitter - Fatal编程技术网

Javascript 从嵌入的twitter时间线解析推特内容

Javascript 从嵌入的twitter时间线解析推特内容,javascript,php,twitter,Javascript,Php,Twitter,我一直在琢磨,拼命地钻研,但没有任何成功。有没有办法挖掘推特的内容/文本,将其放入变量或其他东西中,以备日后使用? 我似乎不知道该如何指出它。 它被隐藏在一百个不同的标签下,时间线在一个iframe中,该iframe在文档准备好后加载(我想)。 而且,奇怪的是,当我开始指向这个iframe内部的任何东西时,timeline似乎就停止工作了(至少对我来说,它根本不显示)(我根本没有碰timeline代码——对于那些怀疑我弄乱了小部件代码的人来说)。 任何帮助都会大有裨益。 感谢使用jQuery,$

我一直在琢磨,拼命地钻研,但没有任何成功。有没有办法挖掘推特的内容/文本,将其放入变量或其他东西中,以备日后使用? 我似乎不知道该如何指出它。 它被隐藏在一百个不同的标签下,时间线在一个iframe中,该iframe在文档准备好后加载(我想)。 而且,奇怪的是,当我开始指向这个iframe内部的任何东西时,timeline似乎就停止工作了(至少对我来说,它根本不显示)(我根本没有碰timeline代码——对于那些怀疑我弄乱了小部件代码的人来说)。 任何帮助都会大有裨益。
感谢使用jQuery,
$('p.js-tweet-text.tweet-text')
应该可以获得页面上的所有tweet。

如果您使用twitter api,只需将$consumerkey、$consumersercret、$accesstoken、$accesstokensecret(只需正弦化并获取密钥)复制我的代码,创建一个类并调用函数getTweets函数,这是非常简单的

    function __construct()
     {
           include_once 'twitterApi/twitteroauth/twitteroauth.php';
           /** set parameter for Twitter Api $consumerkey, $consumersecret, $accesstoken, $accesstokensecret **/
           $this->connection = new TwitterOAuth('xxxxx','xxxx','xxxx-xxx','xxxx');
    }


   function getTweets($twitteruser,$nooftweets=30)
    {   /** fire query by api to get tweets **/
        $tweets = $this->objectToArray($this->connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets));

    /** get all tweets in single array */
    for($i= 0;$i<count($tweets); $i++)
    {
        $create[$i]                 = $tweets[$i]['created_at'];
        $tweet[$i]              = $tweets[$i]['text'];
        $retweetcount[$i]       = $tweets[$i]['retweet_count'];
        $favaritecount[$i]      = $tweets[$i]['favorite_count'];

        /** loop for get multipal #tags **/
        for($j=0;$j<=count($tweets[$i]['entities']['hashtags'])-1;$j++)
        {
            $hastag[$i]             .= $tweets[$i]['entities']['hashtags'][$j]['text'].',';
        }
    }
    return array('Tweet'=>$tweet,'Create'=>$create,'Retweetcount'=>$retweetcount,'Favaritecount'=>$favaritecount,'Hastag'=>$hastag);
}



public function objectToArray($d) {
    if (is_object($d)) {
        // Gets the properties of the given object
        // with get_object_vars function
        $d = get_object_vars($d);
    }

    if (is_array($d)) {
        /*
         * Return array converted to object
        * Using __FUNCTION__ (Magic constant)
        * for recursive call
        */
        return array_map(array($this, 'objectToArray'), $d);
        //$this->d = get_object_vars($d);
    }
    else {
        // Return array
        return $d;
    }
}
函数uuu构造()
{
包括“twitterApi/twitteroauth/twitteroauth.php”;
/**设置Twitter Api的参数$consumerkey、$ConsumerCret、$accesstoken、$accesstokensecret**/
$this->connection=newTwitterOAuth('xxxxx','xxxx','xxxx-xxx','xxxx');
}
函数getTweets($twitteruser,$nooftweets=30)
{/**通过api进行fire查询以获取推文**/
$tweets=$this->objectToArray($this->connection->get(“https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=“$twitteruser.”&count=“.notweets”);
/**在单个数组中获取所有tweet*/
对于($i=0;$i$create,'Retweetcount'=>$Retweetcount,'Favaritecount'=>$Favaritecount,'Hastag'=>$Hastag);
}
公共职能部门反对Array($d){
if(is_object($d)){
//获取给定对象的属性
//使用get_object_vars函数
$d=获取对象变量($d);
}
if(is_数组($d)){
/*
*返回转换为对象的数组
*使用函数(魔法常数)
*用于递归调用
*/
返回数组映射(数组($this,'objectToArray'),$d);
//$this->d=获取对象变量($d);
}
否则{
//返回数组
返回$d;
}
}

您是否考虑过使用twitter API和一些服务器端技术,如ASP.Net或PHP?我希望我可以直接从DOM中获取内容并使用它,而不必深入API。但现在我很沮丧,这可能是最好的主意。在完成这一步之前,我不会得到任何睡眠:)在稍微调整之后,我让它工作了(需要在这些循环之外声明$hastag,并用$hastag[$I]替换$hastag[$I],因为“未定义的偏移量”)。但现在我有一系列漂亮的推特:)再次感谢你。我已经尝试了所有的男人。。。也许我只是做错了,但对于初学者来说,jQuery存在冲突。在那之后,一切似乎都进一步崩溃了。最后,在数百次“刷新”之后,即使时间线本身(以其最纯粹的形式)也会停止工作几分钟。我实在是太笨了,不能参加这个聚会——我想:)