This has do with the way the Twitter API returns the text of a status message. The response will have the text without any HTML, but also specify a set of entities that can be used to "enrich" the text. Entities may be user mentions, url, hashtag or media. You can read more about it here https://dev.twitter.com/docs/entities but it may take some time to get the hang of.
Currently there is limited support in Skybrud.Social for formatting the text, meaning you have to do some work yourself. But you can use the Gist below as starting point:
This will format the text somewhat similar to how it is shown on Twitter.com, but you can also change it to your needs (eg. so links will open in a new window).
It is my plan to add better support for the formatting in the next release ;)
Twitter Example
I have also tried the Twitter example, created the app with Twitter, created data-type, added to document-type.
When I authorize, it authorize just fine and comes back with ID.
I have tried the Twitter.cshtml example. Within foreach loop if i do something like;
@foreach (TwitterStatusMessage status in recent.StatusMessages) {<p>status.Text</p>}
It shows the 'text'; i.e. no HTML, links dont get hyperlinked etc.
Im assuming there should be another property/method to get the RawHtml from the status. ?
Cant seem to locate/find it (tried .Source but that wasnt it). Would appreciate if you can point me on the right direction. Many thanks in advance.
Cheers!
This has do with the way the Twitter API returns the text of a status message. The response will have the text without any HTML, but also specify a set of entities that can be used to "enrich" the text. Entities may be user mentions, url, hashtag or media. You can read more about it here https://dev.twitter.com/docs/entities but it may take some time to get the hang of.
Currently there is limited support in Skybrud.Social for formatting the text, meaning you have to do some work yourself. But you can use the Gist below as starting point:
https://gist.github.com/abjerner/82b5b87ddb0e506c122a
This will format the text somewhat similar to how it is shown on Twitter.com, but you can also change it to your needs (eg. so links will open in a new window).
It is my plan to add better support for the formatting in the next release ;)
Thanks for the insight Anders!
I looked at the gist and that function looks great for what Im trying to get.
However if I add it to a partial @functions { ... }
and then call it within foreach loop like @FormatStatusMessageText(status.Text)
it throws error saying:
CS0246: The type or namespace name 'TwitterBaseEntity' could not be found (are you missing a using directive or an assembly reference?)
This is from the
Line 69: List<TwitterBaseEntity> entities = new List<TwitterBaseEntity>(); Line 70: entities.AddRange(tweet.Entities.HashTags);
I have the following on top of the twitter.cshtml
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using Skybrud.Social.Twitter
@using Skybrud.Social.Twitter.Objects
@using Skybrud.Social.Umbraco.Twitter.PropertyEditors.OAuth
@inherits Umbraco.Web.Mvc.UmbracoViewPage
Is there something obvious that I might be missing?
Cheers!
The class TwitterBaseEntity as well as other entity releated classes have their own namespace, so try adding:
That works Anders!
Then I just have to call it like
@Html.Raw(FormatStatusMessageText(status))
and it works perfectly!
Many thanks!!!
is working on a reply...