示例#1
0
        /// <summary>
        /// gets the tweets
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public TwitterSearchResult GetTweets(string userName, int count)
        {
            TwitterSearchResult retVal = new TwitterSearchResult();

            try
            {
                // Get the access
                var aToken = OuthAuthenticationHelper.GetAccessToken();
                if (aToken.HasAuthToken)
                {
                    string url = string.Format(TwitterConstants.TWEETS_GET_UNFORMATTED_URL,
                                               count, userName);
                    // using the access toke get the tweets
                    var result = HttpUtils.MakeHttpGetRequest(url, aToken.OAuthToken.GetAuthenticationHeaderValue(),
                                                              "application/json");

                    // only id repsosne is ok proceed
                    if (result.ReplyStatusCode == HttpStatusCode.OK)
                    {
                        retVal.Tweets = new JavaScriptSerializer().Deserialize <Tweet[]>(result.ResponseBody);
                    }
                    else
                    {
                        retVal.ErrorMessage = result.ResponseBody;
                    }
                }
            }
            catch (Exception exc)
            {
                retVal.ErrorMessage = exc.Message;
            }
            return(retVal);
        }
示例#2
0
        /// <summary>
        /// gets the tweets
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public TwitterTweetsUserAuth.Models.TwitterSearchResult GetTweets(string userName, int count)
        {
            Models.TwitterSearchResult retVal = new Models.TwitterSearchResult();
            try
            {
                // Get the access
                var aToken = OuthAuthenticationHelper.GetAccessToken();
                if (aToken != null)
                {
                    userName = userName.Replace(" ", "%20");

                    string TWEETS_GET_UNFORMATTED_URL = "https://api.twitter.com/1.1/statuses/user_timeline.json?count={0}&screen_name={1}&trim_user=1&exclude_replies=1";

                    string url = string.Format(TWEETS_GET_UNFORMATTED_URL,
                                               count, userName);
                    // using the access toke get the tweets
                    var result = HttpUtils.MakeHttpGetRequest(url, aToken.OAuthToken.GetAuthenticationHeaderValue(),
                                                              "application/json");

                    // only id repsosne is ok proceed
                    if (result.ReplyStatusCode == HttpStatusCode.OK)
                    {
                        retVal.Tweets = new JavaScriptSerializer().Deserialize <Tweet[]>(result.ResponseBody);
                    }
                    else
                    {
                        retVal.ErrorMessage = result.ResponseBody;
                    }
                }
            }
            catch (Exception exc)
            {
                retVal.ErrorMessage = exc.Message;
            }
            return(retVal);
        }
示例#3
0
        public JsonResult SearchForUsersLike(string Prefix)
        {
            var stringResult = new object { };

            if (!string.IsNullOrEmpty(Prefix))
            {
                try
                {
                    var service = OuthAuthenticationHelper.GetAuthenticatedTwitterService(System.Web.HttpContext.Current);

                    stringResult = service.SearchForUser(
                        new SearchForUserOptions()
                    {
                        Q = Prefix, Count = 10, Page = 1
                    })
                                   .Select(x => new { x.ScreenName, profurl = x.ProfileImageUrl }).ToArray();
                }
                catch (Exception ex)
                {
                    //throw new Exception("Error-" + ex);
                }
            }
            return(Json(stringResult));
        }