コード例 #1
0
ファイル: TwitterModelClass.cs プロジェクト: keno0923/Trc2
        public TwitterModelClass(string ck, string cs, string act, string acts, TwitterViewerForm form)
        {
            /*
            tokens.AccessToken = act;
            tokens.AccessTokenSecret = acts;
            tokens.ConsumerKey = ck;
            tokens.ConsumerSecret = cs;
            */
            tws = new TwitterService(ck, cs, act, acts);

            parentForm = form;

            tws.StreamUser((streamEvent, response) =>
            {
                if (response.StatusCode == 0)
                {
                    if (streamEvent is TwitterUserStreamStatus)
                    {
                        TwitterStatus tweet = ((TwitterUserStreamStatus)streamEvent).Status;
                        parentForm.Invoke((MethodInvoker)delegate
                        {
                            ((Form1)parentForm).InvokedTwitterStatus(tweet);
                        });

                    }else if( streamEvent is TwitterUserStreamDeleteStatus )
                    {
                        TwitterUserStreamDeleteStatus dstatus = streamEvent as TwitterUserStreamDeleteStatus;
                        parentForm.Invoke((MethodInvoker)delegate
                        {
                            ((Form1)parentForm).InvokedDeleteStatus(dstatus.StatusId);
                        });
                    }
                    else if (streamEvent is TwitterUserStreamEvent)
                    {
                        TwitterUserStreamEvent evt = streamEvent as TwitterUserStreamEvent;
                    }
                }
            }
            );

            tws.StreamFilter((streamEvent, response) =>
            {
                if (response.StatusCode == 0)
                {
                    new System.Media.SoundPlayer(@"C:\WINDOWS\Media\Windows Balloon.wav").Play();
                }
            }
            );

            RestClient client = tws._client;
            RestRequest req = tws.PrepareHammockQuery("help/configuration.json");
            RestResponse res = client.Request(req);
            Newtonsoft.Json.Linq.JContainer obj
                = Newtonsoft.Json.JsonConvert.DeserializeObject(res.Content)
                as Newtonsoft.Json.Linq.JContainer;

            int uh, uhs;

            int.TryParse(obj["short_url_length"].ToString(), out uh);
            int.TryParse(obj["short_url_length_https"].ToString(), out uhs);

            Url_http = uh;
            Url_https = uhs;
        }