Exemple #1
0
 public static TwitterApi getInstance()
 {
     if (instance == null)
     {
         instance = new TwitterApi
         {
             OAuthConsumerKey    = "2yeyhTAMl3Euzc2aXSlOA",
             OAuthConsumerSecret = "8yXVBamNBfd82hSbCbBNWPQvto0cjgqVjYuBbLXm0"
         };
     }
     return(instance);
 }
Exemple #2
0
        private void requestReply(Twitter father)
        {
            if (father == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(father.ReplyId) || "null".Equals(father.ReplyId))
            {
                return;
            }
            int     times   = 3;
            string  jsonStr = "";
            Twitter reply   = null;

tryRequest:
            try
            {
                times--;
                jsonStr = TwitterApi.getInstance().GetTwitter(father.ReplyId, null, Proxy);
            }
            catch (Exception)
            {
                if (times >= 0)
                {
                    goto tryRequest;
                }
            }
            try
            {
                reply = paserTwitterFormJson(JSON.Parse(jsonStr));
            }
            catch (Exception) { }
            reply        = location302(reply);
            reply        = requestTruncated(reply);
            reply.Text   = mAtEndNameReg.Replace(mStartAtNameReg.Replace(mStartAtNameReg.Replace(reply.Text, ""), ""), "");
            father.Reply = reply;
        }
Exemple #3
0
        private void recursionReply(Twitter data, ref string fullText, List <string> fullUrl)
        {
            if (string.IsNullOrEmpty(data.ReplyId))
            {
                return;
            }
            int     times   = 3;
            string  jsonStr = "";
            Twitter reply   = null;

tryRequest:
            try
            {
                times--;
                jsonStr = TwitterApi.getInstance().GetTwitter(data.ReplyId, null, Proxy);
            }
            catch (Exception)
            {
                if (times >= 0)
                {
                    goto tryRequest;
                }
            }
            try
            {
                reply = paserTwitterFormJson(JSON.Parse(jsonStr));
            }
            catch (Exception) { }
            reply = location302(reply);
            reply = requestTruncated(reply);
            try
            {
                fullText += mAtEndNameReg.Replace(mStartAtNameReg.Replace(mStartAtNameReg.Replace(reply.Text, ""), ""), "") + ((string.IsNullOrEmpty(reply.ReplyId) || string.Equals(reply.ReplyId, "null")) ? "" : string.Format(" //@{0} ", reply.ReplyUser.ScreenName));
                fullUrl.AddRange(reply.ImgUrls);
                recursionReply(reply, ref fullText, fullUrl);
                data.Reply = reply;
            }catch (Exception) { }
        }
Exemple #4
0
 public override string takePage()
 {
     return(TwitterApi.getInstance().GetTwitters(Uid, lastTake == null || lastTake.Length <= 0 ? null : (lastTake[0] as Twitter).Id, null, Proxy));
 }
Exemple #5
0
        public override BaseData onUse(BaseData data)
        {
            Twitter d = data as Twitter;

            if (d.Reply == null)
            {
                int times = 3;
                if (bool.Parse(d.Truncated))
                {
                    Twitter newData = null;
tryRequest:
                    try
                    {
                        times--;
                        string   tr       = TwitterApi.getInstance().GetTwitter(d.Id, null, Proxy);
                        JSONNode jsonNode = JSON.Parse(tr);
                        newData = paserTwitterFormJson(jsonNode);
                    }
                    catch (Exception)
                    {
                        if (times >= 0)
                        {
                            goto tryRequest;
                        }
                    }
                    if (newData != null)
                    {
                        d = newData;
                    }
                }
                if (!string.IsNullOrEmpty(d.ReplyId) && !string.Equals(d.ReplyId, "null"))
                {
                    string text = mAtEndNameReg.Replace(d.Text, "") + string.Format(" //@{0} ", d.ReplyUser.ScreenName);

                    List <string> urls = new List <string>();
                    urls.AddRange(d.ImgUrls);
                    recursionReply(d, ref text, urls);
                    d.Text    = text.Replace(((TwitterUser)User).ScreenName, ((TwitterUser)User).UserName);
                    d.ImgUrls = urls.ToArray();
                }
                MatchCollection matches = mHttpUriReg.Matches(d.Text);
                foreach (Match match in matches)
                {
                    string location = null;
reTry:
                    try
                    {
                        location = request.Location(match.Value, Proxy, null);
                    }
                    catch (TimeoutException)
                    {
                        goto reTry;
                    }
                    if (!string.IsNullOrEmpty(location))
                    {
                        d.Text = d.Text.Replace(match.Value, location);
                    }
                }
            }

            return(d);
        }