Used this module a few times now and found it very helpful, so thanks.

I'd like to not display any tweets that begin with '@', as these are usually meaningless when displayed out of context on my site. Is there a simple way to achieve this?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

irakli’s picture

Let me ask a different question (I promise, there's a point in it :)): what is the criteria for the stream of tweets that you are trying to display now?

gapple’s picture

This seems like the same thing I'm looking for. I have a personal site and want to pull in my twitter stream, but don't want my @reply messages to show up. The Twitter JavaScript widgets don't do this, but the web interface filters them out if you're not following the recipient as well as the sender.

I used my own tpl, so it was easy enough to filter the tweets there, but then sometimes the stream will be short tweets.

 foreach ($tweets as $tweet_key => $tweet):
    if (substr($tweet->text, 0, 1) == '@') { continue; }
gapple’s picture

Looking through the API documentation, statuses/user_timeline supports filtering replies via the exclude_replies parameter, however it applies the filter after the count and so filtered tweets subtract from the total returned. I was unable to find a corresponding parameter for lists or the search API.

https://dev.twitter.com/docs/api/1/get/statuses/user_timeline

alexmartin’s picture

Thanks for the replies. I've had a play with this and can indeed filter out the "@relipes", but as mentioned by gapple, these get subtracted from the count, meaning I may end up with few or no tweets. I'm not very good with php, but here's a simplified version of my tpl code.

   <?php foreach ($tweets as $tweet_key => $tweet): ?>
      <?php if (substr($tweet->text, 0, 1) != '@'): ?>
         <li>
            <div class="tweet-text"><?php print twitter_pull_add_links($tweet->text); ?></div>
         </li>
      <?php endif; ?>
   <?php endforeach; ?>

Could I instead pull back more tweets (e.g. 20 tweets), then limit the amount of tweets that get printed from the 20 after the filter is applied? Not sure how I'd code this though? It could still fail if there was a very high number of @replies, but as I only want to display 5 tweets, I'm sure that out of the 20, 5 wouldn't be @replies.

gapple’s picture

I ended up doing exactly that, grabbing 10 tweets and having the tpl stop after printing 5 of them.

   <?php $tweet_count = min(count($tweets), 5); ?>
    <ul class="tweets-pulled-listing">
    <?php foreach ($tweets as $tweet_key => $tweet): 
      if (substr($tweet->text, 0, 1) == '@') { $tweet_count++; continue; }
      if ($tweet_key >= $tweet_count) { break; }
    ?>
      <li>
        <!-- tweet -->
      </li>
    <?php endforeach; ?>
    </ul>
alexmartin’s picture

Status: Active » Closed (fixed)

that works brilliantly gapple. Many thanks for your help on this.

gapple’s picture

Status: Closed (fixed) » Active

I think this is worth keeping open for a proper solution that doesn't require TPL changes.

gapple’s picture

Status: Active » Needs review
FileSize
4.91 KB

Here's a simple patch that allows globally filtering replies in user feeds by using a variable. I think it should ultimately be possible to specify per-feed though.

I also added an option for retweets, since it was simple.

davidneedham’s picture

Version: 6.x-1.2 » 7.x-1.x-dev
Category: support » feature
Status: Needs review » Needs work

Wow, this is a tinsy bit old, isn't it? It's no wonder this patch doesn't work anymore. I'll update for 7.x and see if I can reroll this one.

davidneedham’s picture

Eh, consider this blocked until #1781024: Make the Twitter Pull module work when Twitter turns off the version 1 API due to uncertainty of this project.

bnash2501’s picture

If anyone is interested, this can also be solved via applying http://drupal.org/node/1081658 and implementing hook_twitter_pull_tweets_alter and doing a simple regex/substr check on the $tweet->text. Granted, not as elegant as having a nice option available directly from twitter_pull, but may work for some.

wouters_f’s picture

I have made this in to a patch.
You can nicely filter retweets/answers out of the results by adding them as a parameter.
See the attached patch.

cdenneen’s picture

@drupal_sensei

I've extended upon your patch to fix this issue with 7.x-2.x-dev that fixed issues where using NULL values

http://drupal.org/node/1977950

RaulMuroc’s picture

Issue summary: View changes

IT stills catches the repiles.

For example

I tweet " Hei i love #football"

Then reply:

"Me too" <-- this is not catched (NICE!)

Then reply:

"I also love #football" <-- It catches it but i think should not because anyway it has the hashtag it is a Reply!

But somehow when it caches the hashtag just ignores if it is a reply.

RaulMuroc’s picture

Status: Needs work » Active
RaulMuroc’s picture

definetelty doesn't work. Retweets are still coutned and shown as RE @bla bla [text]

gapple’s picture

@RaulMuroc If you send the API request manually with the parameter to exclude replies, do you get the correct response?
Unless this module is sending an incorrect request, it's all up to the Twitter API to filter responses properly.
The raw API response may also have additional information that can help you determine why a tweet may not have been filtered, or that it really is an issue with the API.

gapple’s picture

Status: Active » Closed (duplicate)

It looks like this issue was addressed in #1977950: Enable/Disable Re-Tweets and Replies in Twitter Block Box, so I'll close this as a duplicate