Exemplo n.º 1
0
        private string GetOauthHeader(OauthHeaderType oauthHeaderType, string bearerToken, OAuthSocialNetwork network)
        {
            switch (network)
            {
            case OAuthSocialNetwork.Twitter:
            case OAuthSocialNetwork.LinkedIn:
                return(oauthHeaderType.ToString() + " " + bearerToken);

            case OAuthSocialNetwork.FaceBook:
                return(string.Empty);

            default:
                return(oauthHeaderType.ToString() + " " + bearerToken);
            }
        }
Exemplo n.º 2
0
        private T GetSocalMediaFeedsFromXdoc(string jsonString,
                                             Func <XDocument, IEnumerable <TweetObject> > socialMediaFeedsFromXml, OAuthSocialNetwork network)
        {
            // To convert JSON text contained in string json into an XML node
            WidgetGroupItems = new T();

            dynamic xmldoc = string.Empty;

            if (network.Equals(OAuthSocialNetwork.Twitter))
            {
                xmldoc = JsonConvert.DeserializeXNode("{\"status\":" + jsonString + "}", "root");
            }
            else if (network.Equals(OAuthSocialNetwork.LinkedIn))
            {
                xmldoc = JsonConvert.DeserializeXNode("jsonString");
            }

            var ProfileTweets = socialMediaFeedsFromXml.Invoke(xmldoc);

            foreach (var profileTweet in ProfileTweets)
            {
                var      dateCreated    = profileTweet.TimeCreated;
                string[] timeComponents = dateCreated.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries);
                var      dateComponents = timeComponents[0].Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
                var      year           = timeComponents[1].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[1];
                dateCreated = string.Concat(dateComponents[0].Trim(), " ", dateComponents[1], " ", dateComponents[2], " ", dateComponents[3], " ", year);

                string timeSince = string.Empty;
                try
                {
                    DateTime createdDate = DateTime.ParseExact(dateCreated, "ddd MMM dd HH:mm:ss yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None);
                    DateTime current     = DateTime.Now;

                    TimeSpan period = current - createdDate;

                    GetTimeSinceTweeted(period, out timeSince);
                }
                catch (Exception e)
                {
                    return(default(T));
                }

                WidgetGroupItems.Add(new GroupObject {
                    GroupActionText = _groupActionText, GroupActionUrl = _groupActionUrl, GroupDescription = AddColourToTwitterKnownWords(profileTweet.Tweet), GroupAvatarUrl = profileTweet.AvatarUrl, GroupId = -1, GroupHeaderText = _groupHeaderText, GroupUrl = profileTweet.GroupUrl, Username = profileTweet.Username, Duration = timeSince, TweetStatusId = profileTweet.StatusId, MediaUrl = profileTweet.MediaUrl, MediaSizeX = profileTweet.MediaSizeX, MediaSizeY = profileTweet.MediaSizeY, MediaType = profileTweet.MediaType
                });
            }


            //int cacheTime = 180;
            //Int32.TryParse(cacheTimeSecs, out cacheTime);
            //Cache.Insert(cacheKey, WidgetGroupItems, null, DateTime.UtcNow.AddSeconds(cacheTime), System.Web.Caching.Cache.NoSlidingExpiration);
            //return WidgetGroupItems.ToSerializerXml();
            return(WidgetGroupItems);
        }
Exemplo n.º 3
0
        private string GetOauthHeader(OauthAuthentication oauthentication, OauthHeaderType oauthHeaderType,
                                      OAuthSocialNetwork network)
        {
            var oauth_version          = "1.0";
            var oauth_signature_method = "HMAC-SHA1";
            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();

            var baseFormat = string.Empty;
            var baseString = string.Empty;

            if (network.Equals(OAuthSocialNetwork.Twitter))
            {
                baseFormat = "oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}" +
                             "&oauth_timestamp={3}&oauth_token={4}&oauth_version={5}";
                baseString = string.Format(baseFormat,
                                           oauthentication.ConsumerKey,
                                           oauth_nonce,
                                           oauth_signature_method,
                                           oauth_timestamp,
                                           oauthentication.TokenKey,
                                           oauth_version
                                           );
            }
            else if (network.Equals(OAuthSocialNetwork.LinkedIn))
            {
                baseFormat = "oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}" +
                             "&oauth_timestamp={3}&oauth_callback={4}&oauth_version={5}&client_id={6}&redirect_uri={7}&scope=r_fullprofile%20w_share&state=MezZanillionsxein2859";
                baseString = string.Format(baseFormat,
                                           oauthentication.ConsumerKey,
                                           oauth_nonce,
                                           oauth_signature_method,
                                           oauth_timestamp,
                                           HttpContext.Current.Request.Url.AbsoluteUri,
                                           oauth_version,
                                           oauthentication.ClientAppId,
                                           HttpContext.Current.Request.Url.AbsoluteUri
                                           );
            }



            var compositeKey = string.Concat(Uri.EscapeDataString(oauthentication.ConsumerSecret),
                                             "&", Uri.EscapeDataString(oauthentication.TokenSecret));

            string oauth_signature;

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

            var headerFormat = oauthentication.ConsumerKey + ":" + oauthentication.ConsumerSecret;

            headerFormat = Convert.ToBase64String(ASCIIEncoding.UTF8.GetBytes(headerFormat));

            return(oauthHeaderType.ToString() + " " + headerFormat);
        }