Copied to clipboard

Flag this post as spam?

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


  • Tizer 170 posts 201 karma points
    Jul 21, 2013 @ 09:45
    Tizer
    0

    How to use GetUserTweets

    Thanks for creating this package - very handy :)

    I am trying to change the user of the tweets returned in uTweet.LatestTweet.cshtml and am failing.

    I have changed the file to this (where twitteruser is the account I want to display tweets from):

    @{
        try
        {
        var t = new uTweets.Tweets();
        var result = t.GetUserTweets(twitteruser);
       
        if (result != null)
        {
            @Html.Raw(result.First().TextAsHtml)
        }
        }
        catch (Exception ex)
        {
            @ex.ToString();
        }
    }

    I'm not sure how to use the (string screenName) with GetUserTweets .

  • Nick Garrard & Davy Belmans 25 posts 142 karma points
    Jul 22, 2013 @ 17:06
    Nick Garrard & Davy Belmans
    0

    Hi, your code does seem to be working. I changed twitteruser to "umbraco" (without @) and I got one tweet from @umbraco.

    Does your twitter user have any recent tweets? I read in the twitter api docs that not all tweets can be retrieved with the api. (https://dev.twitter.com/docs/faq#8650)  The api will only return the latest (and relevant, whatever that means) tweets for a week or so. 

    regards,

    davy

  • Tizer 170 posts 201 karma points
    Jul 23, 2013 @ 01:46
    Tizer
    0

    Hi - yes sorry, I forgot to reply, it is working using this:

    var result = t.GetUserTweets("umbraco");

    I was getting an previously when saving before, but now I think it was some kind of server error.

    Thanks for the reply - great package :)

  • Niels 63 posts 119 karma points
    Jul 24, 2013 @ 11:10
    Niels
    0

    I've also a question about GetUserTweets:

    I have an umbraco multi-site instance with multiple twitteraccounts and used the uTweet.ListOfTweets as example for my own code:

    @{
        int nrOfTweets = String.IsNullOrEmpty(Parameter.nrOfTweets) ? 10 : int.Parse(Parameter.nrOfTweets);
    
        try
        {
        var t = new uTweets.Tweets();
        var username = Model._twitterLink;
        var result = t.GetUserTweets(username.ToString());
        if (result != null)
        {
                foreach(var tw in result.Take(nrOfTweets))
                {
                    <div class="tweet">
                        <p>
                            @Html.Raw(tw.TextAsHtml)
                            <span>@tw.CreatedDate</span> 
                        </p>
                    </div>
                }
        }
        }
        catch (Exception ex)
        {
            @ex.ToString();
        }
    } 

    But I'm getting the following error:

    Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'object' does not contain a definition for 'Take'
       at CallSite.Target(Closure , CallSite , Object , Int32 )
       at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
       at ASP._Page_macroScripts_uTweet_ListOfTweets_cshtml.Execute() 
  • Niels 63 posts 119 karma points
    Jul 24, 2013 @ 11:23
    Niels
    0

    Never mind I've found the solution for my problem:

    @{
    
        int nrOfTweets = String.IsNullOrEmpty(Parameter.nrOfTweets) ? 10 : int.Parse(Parameter.nrOfTweets);
    
        try
        {
        string screenname = Model._twitterLink;
        var tResult = new uTweets.Tweets().GetUserTweets(screenname).Take(nrOfTweets);
    
        if (tResult != null)
        {
                foreach(var tw in tResult)
                {
                    <div class="tweet">
                        <p>
                            @Html.Raw(tw.TextAsHtml)
                            <span>@tw.CreatedDate</span> 
                        </p>
                    </div>
                }
        }
        }
        catch (Exception ex)
        {
            @ex.ToString();
        }
    } 
Please Sign in or register to post replies

Write your reply to:

Draft