Quantcast
Channel: Tweetinvi a friendly Twitter C# library
Viewing all articles
Browse latest Browse all 4126

Commented Unassigned: HashTags are null with Tweet with photo [2548]

$
0
0
Consider the following code:

```
//Tweet 588403629956190209:
//When live gives you lemons... #motivational http://t.co/YvofkvOS8J

var tweet = Tweet.GetTweet(588403629956190209);

if (tweet.Hashtags == null || tweet.Hashtags.Count != 1)
{
throw new Exception("We have a problem. Hashtags are not okay.");
}
```

When I use a photo (might be a link), the HashTags collection remains null. It should have 1 "#motivational". I've encountered this behavior also when I'm reading the tweet from a timeline.

Using release 0.9.6.0.
Comments: ** Comment from web user: KeesCBakker **

As I workaround I used the following extension class to parse the tags myself:

```
public static class TweetInviExtensions
{
public static IList<string> GetHashTags(this ITweet tweet)
{
if (tweet.Hashtags != null)
{
return tweet.Hashtags.OrderBy(h => h.Text).Select(h => h.Text).ToList();
}
else if (tweet.Text != null && tweet.Text.IndexOf("#") != -1)
{
return Regex.Matches(tweet.Text, @"#\w+").Cast<Match>().Select(m => m.Value.Substring(1)).ToList();
}

return Enumerable.Empty<string>().ToList();
}

public static IList<string> GetUserMentions(this ITweet tweet)
{
if (tweet.Hashtags != null)
{
return tweet.UserMentions.OrderBy(u => u.ScreenName).Select(u => u.ScreenName).ToList();
}
else if (tweet.Text != null && tweet.Text.IndexOf("@") != -1)
{
return Regex.Matches(tweet.Text, @"@\w+").Cast<Match>().Select(m => m.Value.Substring(1)).ToList();
}

return Enumerable.Empty<string>().ToList();
}

public static void ForEach<T>(this IEnumerable<T> list, Action<T> action)
{
foreach(var item in list)
{
action(item);
}
}

public static bool Exists<T>(this IEnumerable<T> list, Func<T, bool> func)
{
foreach (var item in list)
{
if (func(item))
{
return true;
}
}

return false;
}
}

```


Viewing all articles
Browse latest Browse all 4126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>