2012-04-27 5 views
0

私は、最新のツイート機能をウェブサイトに設定しました。クライアントは、「最新のつぶやき」として表示されるのを止めるために@mentionsを非表示にするよう求めています。私はTwitter APIを見てきましたが、正直言って、これについてはほとんど知識がありませんでした。したがって、これをどうやって行うのか、本当に頭を悩ますことはできません。あるいはそれが可能であっても。「最新のツイート」から@mentionsを隠す

私は「最新のつぶやき」を呼び出すために使用します。このコードは

<?php 
      // Your twitter username. 
      $username = "****"; 

      // Prefix - some text you want displayed before your latest tweet. 
      // (HTML is OK, but be sure to escape quotes with backslashes: for example href=\"link.html\") 
      $prefix = ""; 

      // Suffix - some text you want display after your latest tweet. (Same rules as the prefix.) 
      $suffix = ""; 

      $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1"; 

      function parse_feed($feed) { 
       $stepOne = explode("<content type=\"html\">", $feed); 
       $stepTwo = explode("</content>", $stepOne[1]); 
       $tweet = $stepTwo[0]; 
       $tweet = str_replace("&lt;", "<", $tweet); 
       $tweet = str_replace("&gt;", ">", $tweet); 
       return $tweet; 
      } 

      $twitterFeed = file_get_contents($feed); 
      echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix); 
     ?>​ 

任意の助けいただければ幸いです。

答えて

0

試みは、あなたにしているの復帰を変更:

if(!preg_match("/@(\w+)/", $tweet)) 
{ 
    return $tweet; 
} 
else 
{ 
    return ""; 
} 
+0

でサンプルコードだから、このことだろうか? [link](http://jsfiddle.net/CNAGb/1/) – kelvin1986

+0

そのコードはまだコードを返すようです。私はあなたの指示を誤解していると思います。 – kelvin1986

0

それはあなたがユーザーの最新のつぶやきを取得し、@さんをフィルタリングしたいかのように思えます。検索の呼び出しを避け、代わりにtimeline callに注目します。コールの各項目に添付

は、これらのフィールドは

"in_reply_to_status_id": null, 
"in_reply_to_status_id_str": null, 
"in_reply_to_user_id": null, 
"in_reply_to_user_id_str": null, 
"in_reply_to_screen_name": null, 

"in_reply_to_status_id""in_reply_to_status_id_str"null残る場合がありますが、それはまだ@返事かもしれないです。あなたの探しているものは"in_reply_to_screen_name"です。名前が記入されている場合は@です。電話をかけるとき

は、単にin_reply_to_screen_name != null

は、同様にあなたがテストできるところdeveloper consoleを見てみましょう&試合をミックスアイテムを無視します。

- PHP☟

<?php 
$json = file_get_contents("http://twitter.com/status/user_timeline/twitterapi.json", true); 
$decode = json_decode($json, true); //PHP Array output from twitter JSON 

$valid = array(); 
$count = count($decode); //counting the number of status 
for($i=0;$i<$count;$i++){ 
    if(!$decode[$i]['in_reply_to_screen_name']){ 
     array_push($valid, $decode[$i]); 
    } 
}; 

print_r($valid); //tweets that are not @ replies 
?> 
+0

ご協力ありがとうございます。うんざりして私はAPIの周りに私の頭を得ることができません。私はこれをどのように実装するのか本当に理解していない。私は 'exclude_replies = true'フィールドを使用する必要があると推測していますが、それは私が持っている限りです:( – kelvin1986

+0

実際にあなたは呼び出しを行うことができます。 – Chamilyan

関連する問題