2013-09-21 26 views
0

我一直在想,並且拼命地挖掘它沒有任何成功。有什麼方法可以挖掘推文的內容/文字,將它放在一個變量或其他東西中 - 供以後使用? 這似乎是我的頭如何指出它的方式。 它被埋在一百個不同的標籤下,時間軸在一個iframe裏面,這個iframe在文檔準備就緒(我想)之後加載。另外,奇怪的是,只要我開始在這個iframe裏面指出任何東西(我根本沒有觸及時間軸代碼 - ),時間線似乎根本不會工作(至少對我來說 - 它根本不顯示)對於那些會懷疑我搞砸小部件代碼的人)。 任何幫助都會非常有幫助。 謝謝從嵌入式twitter時間線解析tweet內容

+0

你有沒有考慮過使用twitter API和一些服務器端技術作爲ASP.Net或PHP? – Tony

+0

我希望我可以直接從DOM獲取內容,並且無需深入API即可使用它。但現在我很沮喪,這可能是最好的想法。直到完成這一步之後纔會有任何睡眠:) – cyvvilek

回答

0

這是非常簡單的,如果你使用Twitter的API只是把$ consumerkey,$ consumersecret,$的accessToken,$ accesstokensecret(只是正弦了https://dev.twitter.com/docs/auth/sign-twitter,並得到鑰匙)複製我的代碼,使類和調用函數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; 
    } 
} 
+0

你救了我的命! – cyvvilek

+0

經過一點調整後,我得到了它的工作(需要在這些循環之外聲明$ hastag,並用$ hastag []替換$ hastag [$ i],因爲'undefined offset')。但現在我有一個美麗的微博陣列:)再次感謝你。 – cyvvilek

+0

這是我的舊代碼,我在舊項目中使用了它 –

0

使用jQuery,$('p.js-tweet-text.tweet-text')應該讓你在頁面上的所有推文。

+0

我試過所有那個人......也許我只是做了這個錯誤,但是對於初學者來說存在jQuery衝突。之後 - 一切似乎都進一步崩潰。最後,在「刷新」的情況下 - 甚至時間線本身(以其最純粹的形式)停止工作幾分鐘。我對這個問題太傻了 - 我猜:) – cyvvilek