2

I have been attempting to figure out how to add a Twitter feed to one of my SharePoint 2010 pages and it seems like there is no way short of building a custom Web Part to do so now that Twitter has shut down version 1.0 of their API. At least it seems that way given that everything I find either relates to Version 1.0 of the API or SharePoint 2013.

Am I missing something here? Is there a way with a SharePoint 2010 Web Part to make this work?

Thanks, Doug

2

I'm not sure what are you going to do, so here is different options.

  1. If you want to show tweets from company's account, you can try to use embedded timeline. It's ready-to-use script, you just need to add it to your page (for example, with Content Editor Web Part). It's not customizable though.

  2. If previous solution doesn't fit, you can use some scripts on JS. I found this, but I'm sure there are lots of them.

  3. You can also develop your own solution. It's not very complicated, there are a lot of libraries for twitter api, both on JS and C#.

p.s. I could't find solutions for SP2013, but if you did, you can use them for SP2010, just recompile them from source code for .NET3.5

  • Thanks for the replay. I tried the first option above and for a fleeting second it looked like it was going to work. I added the Content Editor Web Part and copied the HTML from the Twitter Widgets Configurator and for a brief second it displayed the tweets as I expected them and them immediately collapsed to nothing but a link and that's how it's stayed. Is there something I need to do in the configuration for the web part to make it work properly? – dscarr Dec 16 '13 at 21:38
  • All I really want is for the most recent five or so tweets from my company Twitter feed to show up on my SharePoint page. No editing or re-tweeting or replying would be the best but at this point I'll take what I can get. – dscarr Dec 16 '13 at 22:16
1

create a new web application in C# and copy this code to the Page Load function. Replace the "consumerKey, consumerSecret, accessToken, accessTokenSecret" with your own key details and run the application.

        // oauth application keys
        var consumerKey = "Your Key";
        var consumerSecret = "Your Key";
        var accessToken = "Your Key";//oauth_token
        var accessTokenSecret = "Your Key";//oauth_token_secret
        var Count = "3";

        // oauth implementation details
        var oauthSignatureMethod = "HMAC-SHA1";
        var oauthVersion = "1.0";
        // message api details
        //var status = "Updating status via REST API if this works";
        var resource_url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
        var screen_name = "TransPerth";

        // unique request details
        var oauth_nonce = Convert.ToBase64String(
           new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()));
        var timeSpan = DateTime.UtcNow
            - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
        var oauth_timestamp = Convert.ToInt64(timeSpan.TotalSeconds).ToString();

        // create oauth signature
        var baseFormat = "count={7}&oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}" +
                        "&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}&screen_name={6}";
        var baseString = string.Format(baseFormat,
                                    consumerKey,
                                    oauth_nonce,
                                    oauthSignatureMethod,
                                    oauth_timestamp,
                                    accessToken,
                                    oauthVersion,
                                     Uri.EscapeDataString(screen_name),
                                     Uri.EscapeDataString(Count)
                                    );

        baseString = string.Concat("GET&", Uri.EscapeDataString(resource_url), "&", Uri.EscapeDataString(baseString));

        var compositeKey = string.Concat(Uri.EscapeDataString(consumerSecret),
                                "&", Uri.EscapeDataString(accessTokenSecret));

        string oauth_signature;
        using (HMACSHA1 hasher = new HMACSHA1(ASCIIEncoding.ASCII.GetBytes(compositeKey)))
        {
            oauth_signature = Convert.ToBase64String(
                hasher.ComputeHash(ASCIIEncoding.ASCII.GetBytes(baseString)));
        }

        // create the request header
        var headerFormat = "OAuth oauth_nonce=\"{0}\", oauth_signature_method=\"{1}\", " +
                           "oauth_timestamp=\"{2}\", oauth_consumer_key=\"{3}\", " +
                           "oauth_token=\"{4}\", oauth_signature=\"{5}\", " +
                           "oauth_version=\"{6}\"";

        var authHeader = string.Format(headerFormat,
                                Uri.EscapeDataString(oauth_nonce),
                                Uri.EscapeDataString(oauthSignatureMethod),
                                Uri.EscapeDataString(oauth_timestamp),
                                Uri.EscapeDataString(consumerKey),
                                Uri.EscapeDataString(accessToken),
                                Uri.EscapeDataString(oauth_signature),
                                Uri.EscapeDataString(oauthVersion)
                        );

        // make the request
        ServicePointManager.Expect100Continue = false;

        var postBody = string.Format("screen_name={0}&count={1}", Uri.EscapeDataString(screen_name), Uri.EscapeDataString(Count));
        resource_url += "?" + postBody;
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(resource_url);
        request.Headers.Add("Authorization", authHeader);
        request.Method = "GET";
        request.ContentType = "application/x-www-form-urlencoded";

        WebResponse response = request.GetResponse();
        string responseData = new StreamReader(response.GetResponseStream()).ReadToEnd();
        //Label1.Text = responseData;
  • 2
    I think, adding a link to original solution where you copy-paste it from, is a good practice. Here is also a thread with this and other examples. – Evgenii Vilkov Dec 16 '13 at 17:36
  • Can I take it from this response and the comment that follows that I am correct? That this cannot be done using a current web part in SharePoint 2010 and must include custom development? – dscarr Dec 16 '13 at 18:24
0

The easiest way I found to embed the Twitter feed into Sharepoint 2010 is to get the feeds 'embedded timeline' widget, paste the html and javascript into a html file, upload the file into a document library, then display the uploaded page in a page viewer webpart. Don't use a content editor webpart - the html/javascript gets modified when saving the contents.

You can set the height of the page viewer webpart and the widget (in the widget configurator) - I had to set the height of the web part to be about 50px higher in the webpart to avoid multiple scrollbars.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.