示例#1
0
 protected void FetchReply(TwitterMessage twitterMessage)
 {
     if (twitterMessage.InReplyToId > 0)
     {
         SendLoadingMessage("Loading reply");
         MyWebClient client = new MyWebClient();
         client.OAuthHelper = OAuthHelper;
         //TwitterClient client = new TwitterClient();
         client.DoPostCompleted += (o, e) =>
         {
             if (e.Error == null)
             {
                 TwitterMessage newMessage = new TwitterMessage(XElement.Parse(e.Response));
                 // Create a new
                 int index = Messages.IndexOf(twitterMessage);
                 Messages.Insert(index, newMessage);
                 SendLoadedMessage("Reply loaded");
                 CurrentMessage = newMessage;
             }
             else
             {
                 SendErrorMessage("Error Fetching Reply");
             }
         };
         client.DoGetAsync(new Uri(string.Format("http://api.twitter.com/1/statuses/show/{0}.xml", twitterMessage.InReplyToId), UriKind.Absolute));
     }
 }
示例#2
0
        private void OlderPostsUpTo(long currentID, long maxID)
        {
            MyWebClient getUserMessages = new MyWebClient();

            getUserMessages.OAuthHelper      = OAuthHelper;
            getUserMessages.DoPostCompleted += (sender, e) =>
            {
                if (e.Error != null)
                {
                    SendErrorMessage(e.Error.Message);
                }
                else
                {
                    int             currentCount = fetchList.Count;
                    XElement        element      = XElement.Parse(e.Response);
                    TwitterTimeline timeline     = new TwitterTimeline(element);
                    //var newmessages = AddNewMessages(timeline).ToList();
                    fetchList.AddRange(timeline);                    //newmessages);
                    fetchList = fetchList.Distinct(new CompareTwitters()).ToList();
                    //foreach (var mess in newmessages)
                    //{
                    //    _timelineMessages.Add(mess);
                    //}



                    if (fetchList.Count > currentCount)
                    {
                        if (fetchList.Min(m => m.ActualId) > currentID)
                        {
                            SendLoadingMessage("Loaded " + timeline.Count.ToString() + "... Still loading");
                            long newMaxId = fetchList.Min(m => m.ActualId);
                            OlderPostsUpTo(currentID, newMaxId);
                            return;
                        }
                    }

                    _timelineMessages.Clear();
                    foreach (var mess in fetchList.OrderBy(m => m.ActualId))
                    {
                        _timelineMessages.Add(mess);
                    }
                    SendLoadedMessage("Finished Loading timeline");
                    FirePropertyChanged("Messages");
                    CurrentMessage = Messages.FirstOrDefault(m => m.ActualId == currentID);
                }
            };
            if (maxID == 0)
            {
                getUserMessages.AddParameters(Params("count", "200", "include_entities", "true"));
                //uri = "http://api.twitter.com/1/statuses/home_timeline.xml?count=200";
            }
            else
            {
                getUserMessages.AddParameters(Params("count", "200", "max_id", maxID.ToString()));
                //uri = "http://api.twitter.com/1/statuses/home_timeline.xml?count=200&max_id=" + maxID.ToString();
            }
            getUserMessages.DoGetAsync(new Uri("http://api.twitter.com/1/statuses/home_timeline.xml", UriKind.Absolute));
        }
示例#3
0
        private void AuthorizeCommand()
        {
            MyWebClient client = new MyWebClient();
            OAuthHelper oauth  = new OAuthHelper();

            oauth.Token       = OAuthToken;
            oauth.Verifier    = Verifier;
            oauth.TokenSecret = OAuthTokenSecret;
            oauth.CreateSignature("https://api.twitter.com/oauth/access_token", "GET");
            string auth = oauth.AuthenticationHeader;

            client.SetHeader("Authorization", auth);
            client.DoPostCompleted += new EventHandler <DoPostCompletedEventArgs>(AuthCompleted);
            client.DoGetAsync(new Uri("https://api.twitter.com/oauth/access_token", UriKind.Absolute));
        }
示例#4
0
        protected void FetchTimeline(string Uri, IEnumerable <KeyValuePair <string, string> > parameters, string error, bool ShowFirst = false)
        {
            SendLoadingMessage("Fetching messages");
            MyWebClient getUserMessages = new MyWebClient();

            getUserMessages.OAuthHelper = OAuthHelper;
            getUserMessages.AddParameters(parameters);
            bool showfirst = ShowFirst;

            getUserMessages.DoPostCompleted += (sender, e) =>
            {
                if (e.Error != null)
                {
                    SendErrorMessage(error);
                }
                else
                {
                    XElement        element  = XElement.Parse(e.Response);
                    TwitterTimeline timeline = new TwitterTimeline(element);
                    var             added    = AddNewMessages(timeline).ToList();
                    foreach (var mess in added)
                    {
                        _timelineMessages.Add(mess);
                    }
                    if (added.Count > 0)
                    {
                        if (showfirst)
                        {
                            CurrentMessage = added.FirstOrDefault();
                        }
                        SendLoadedMessage(added.Count.ToString() + " Messages loaded");
                    }
                    else
                    {
                        SendLoadedMessage("No messages loaded");
                    }
                }
            };

            getUserMessages.DoGetAsync(new Uri(Uri, UriKind.Absolute));
        }
示例#5
0
        public AuthViewModel()
        {
            _AuthorizeCommand = new RelayCommand(AuthorizeCommand, CanAuthorizeCommand);
            var settings = IsolatedStorageSettings.ApplicationSettings;
            if (OAuthDetails.IsAuthenticated)
            {
                OAuthToken = OAuthDetails.Token;
                OAuthTokenSecret = OAuthDetails.TokenSecret;
                IsAuthorized = true;
            }
            else
            {
                MyWebClient client = new MyWebClient();
                OAuthHelper oauth = new OAuthHelper();

                oauth.Callback = "oob";
                oauth.ConsumerKey = OAuthDetails.ConsumerKey;
                oauth.ConsumerSecret = OAuthDetails.ConsumerSecret;
                client.OAuthHelper = oauth;
                client.DoPostCompleted += new EventHandler<DoPostCompletedEventArgs>(GotRequestToken);
                client.DoGetAsync(new Uri("https://api.twitter.com/oauth/request_token", UriKind.Absolute));

            }
        }
示例#6
0
        public AuthViewModel()
        {
            _AuthorizeCommand = new RelayCommand(AuthorizeCommand, CanAuthorizeCommand);
            var settings = IsolatedStorageSettings.ApplicationSettings;

            if (OAuthDetails.IsAuthenticated)
            {
                OAuthToken       = OAuthDetails.Token;
                OAuthTokenSecret = OAuthDetails.TokenSecret;
                IsAuthorized     = true;
            }
            else
            {
                MyWebClient client = new MyWebClient();
                OAuthHelper oauth  = new OAuthHelper();

                oauth.Callback          = "oob";
                oauth.ConsumerKey       = OAuthDetails.ConsumerKey;
                oauth.ConsumerSecret    = OAuthDetails.ConsumerSecret;
                client.OAuthHelper      = oauth;
                client.DoPostCompleted += new EventHandler <DoPostCompletedEventArgs>(GotRequestToken);
                client.DoGetAsync(new Uri("https://api.twitter.com/oauth/request_token", UriKind.Absolute));
            }
        }
示例#7
0
        private void AuthorizeCommand()
        {
            MyWebClient client = new MyWebClient();
            OAuthHelper oauth = new OAuthHelper();

            oauth.Token = OAuthToken;
            oauth.Verifier = Verifier;
            oauth.TokenSecret = OAuthTokenSecret;
            oauth.CreateSignature("https://api.twitter.com/oauth/access_token", "GET");
            string auth = oauth.AuthenticationHeader;
            client.SetHeader("Authorization", auth);
            client.DoPostCompleted += new EventHandler<DoPostCompletedEventArgs>(AuthCompleted);
            client.DoGetAsync(new Uri("https://api.twitter.com/oauth/access_token", UriKind.Absolute));
        }