Copied to clipboard

Flag this post as spam?

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


  • Jamie 3 posts 23 karma points
    Nov 17, 2014 @ 15:38
    Jamie
    0

    Where to put custom code

    Hi all.

    I am looking add custom code to an Umbraco 7 site. I have done this a number of times before using a razor script/ macro and also by using a surface controller for a contact form.

    What I require now is a little different. I have created a simple twitter feed for the website and would like to show it on a number of templates. I have tried to use the above without any success. I cannot use the razor script and macro approach as I need to reference an external dll and it keeps complaing.
    I have tried to use the surface controller approach but the code for the controller doesnt seem to run on a get, only on a post.

    Maybe I am doing something incorrect or maybe its the wrong way to do these type of things.

    Can any body please advise? Are any of the above the correct approach? if not, do you have a link for any tutorials/documentaion of how to do this correctly?

    Many thanks

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 17, 2014 @ 15:50
    Jan Skovgaard
    0

    Hi Jamie and welcome to our :)

    Your code is missing from the post so could you please try adding it again? If you're using the markdown editor then make sure to mark the code part and click on the button with the "101010" numbers.

    Cheers, Jan

  • Jamie 3 posts 23 karma points
    Nov 17, 2014 @ 15:55
    Jamie
    0

    Hi Jan,

    Thanks for your help. Here is my code. This is using LinqToTwitter. TwoTweet is my model with two strings.

    public class TwitterSurfaceController : SurfaceController
        {
            // GET: TwitterSurface       
            public ActionResult GetLatestTweets()
            {
                string API_key = "";
                string API_secret = "";
                string Access_token_secret = "";
                string Access_token = "";
    
                var auth = new SingleUserAuthorizer
                {
                    CredentialStore = new SingleUserInMemoryCredentialStore
                    {
                        ConsumerKey = "",
                        ConsumerSecret = "",
                        AccessToken = Access_token,
                        AccessTokenSecret = Access_token_secret
                    }
                };
                var twitterCtx = new TwitterContext(auth);
                try
                {
                    var tweetResponse =
                      (from tweet in twitterCtx.Status
                       where tweet.Type == StatusType.User &&
                             tweet.ScreenName == "" &&
                             tweet.IncludeRetweets == true
                       select tweet).Take(2).ToList();
    
                    var TwoTweet = new TwoTweet { Tweet1 = tweetResponse[0].Text, Tweet2 = tweetResponse[1].Text };
    
                    return PartialView("GetLatestTweets",TwoTweet);
    
                }
                catch (Exception ex)
                {
    
                }
                return PartialView("GetLatestTweets", new TwoTweet { });
            }
        }
    
  • Jamie 3 posts 23 karma points
    Nov 18, 2014 @ 10:22
    Jamie
    0

    Sorry to bump this. I am just eager to try and do things the correct way and not just hack things together.

    Thanks

  • shantanuchandra 1 post 21 karma points
    May 12, 2020 @ 02:27
    shantanuchandra
    0

    Hey, Curious to know if you figured it out. I am trying to do something similar

Please Sign in or register to post replies

Write your reply to:

Draft