私は疑問に思い、必死に掘り下げてきましたが、成功しませんでした。後で使用するために、ツイートのコンテンツ/テキストを掘り出し、変数などに入れる方法はありますか? それをどのように指し示すかは、私の頭をはるかに超えているようです。それは何百もの異なるタグの下に埋もれており、タイムラインはドキュメントの準備ができた後に読み込まれる iframe 内にあります (私はそう思います)。また、奇妙なことに、このiframe内で何かを指し始めるとすぐに、タイムラインがまったく機能しなくなったようです(少なくとも私にとっては-まったく表示されません)(タイムラインコードにはまったく触れていません-私がウィジェットのコードをめちゃくちゃにしたのではないかと疑う人)。どんな助けでも素晴らしく役に立ちます。ありがとう
2 に答える
0
jQuery を使用$('p.js-tweet-text.tweet-text')
すると、ページ上のすべてのツイートを取得できます。
于 2013-09-21T06:30:46.273 に答える
0
$consumerkey、$consumersecret、$accesstoken、$accesstokensecret を配置するだけの Twitter API を使用する場合は非常に簡単です ( 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;
}
}
于 2013-09-21T06:48:59.677 に答える