Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • keilo 568 posts 1023 karma points
    Aug 02, 2014 @ 21:59
    keilo
    0

    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!

  • Anders Bjerner 487 posts 2989 karma points MVP 7x admin c-trib
    Aug 02, 2014 @ 22:26
    Anders Bjerner
    100

    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 ;)

  • keilo 568 posts 1023 karma points
    Aug 02, 2014 @ 22:48
    keilo
    0

    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!


  • Anders Bjerner 487 posts 2989 karma points MVP 7x admin c-trib
    Aug 02, 2014 @ 23:00
    Anders Bjerner
    1

    The class TwitterBaseEntity as well as other entity releated classes have their own namespace, so try adding:

    @using Skybrud.Social.Twitter.Entities
    
  • keilo 568 posts 1023 karma points
    Aug 02, 2014 @ 23:06
    keilo
    0

    That works Anders!

    Then I just have to call it like 

    @Html.Raw(FormatStatusMessageText(status))

    and it works perfectly!

    Many thanks!!!

Please Sign in or register to post replies

Write your reply to:

Draft