Open Alex-451 opened 3 years ago
twitter.com/user/status/tweetid
gives you the original tweet url. Where is the problem?
I didn't really find a way..
You can't stream/filter to text 'in' an URL, or a domain or something, which is sad.
You could get the original with something like this (Don't, see next comment):
static HttpClientHandler HttpClientHandler { get; set; } = new HttpClientHandler()
{
AllowAutoRedirect = false
};
static Regex TwitterLinkRegex = new Regex("(?<Link>https://t.co/[a-zA-Z0-9]{10})");
MatchCollection twitterLinkMatchCollection = TwitterLinkRegex.Matches(eventReceived.Tweet.Text);
foreach (Match twitterLinkMatch in twitterLinkMatchCollection)
{
string url = twitterLinkMatch.Groups["Link"].Value;
try
{
HttpResponseMessage httpResponseMessage = await HttpClient.SendAsync(new HttpRequestMessage
{
RequestUri = new Uri(url),
Method = HttpMethod.Head
}, HttpCompletionOption.ResponseHeadersRead);
if (httpResponseMessage.IsSuccessStatusCode && httpResponseMessage.Headers?.Location != null)
{
string realUrl = httpResponseMessage.Headers.Location.ToString();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
@KoalaBear84 does Twitter shorten the urls or is that something the wrapper does?
Hmm.. Good question 😂
I see that the info I would like is already present in the JSON / model. So we don't need the above code which is great.
See example:
Have you checked out the latest comment? @AlexanderGipp
Yeah i did, did you manage to actually use that property @KoalaBear84?
The Urls property works, and you can easily loop through it, in reverse, and replace this.
For example like this:
string text = tweet.Text;
List<Tweetinvi.Models.Entities.IUrlEntity>? urls = tweet.Urls;
urls.Reverse();
foreach (Tweetinvi.Models.Entities.IUrlEntity? url in urls)
{
text = text.Remove(url.Indices[0], url.Indices[1] - url.Indices[0]);
text = text.Insert(url.Indices[0], url.ExpandedURL);
}
Or use DisplayedURL
.
Urls in the text of a tweet get changed (shortened) is there a way to get the text of tweets without the replaced urls?