コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            BitlyService s = new BitlyService("bitlyapidemo", "R_0da49e0a9118ff35f52f629d2d71bf07");
            string       shortened;
            StatusCode   status = s.Shorten("http://cnn.com", out shortened);

            IBitlyResponse[] shortUrls = s.Shorten(new string[] { "http://cnn.com", "http://google.com" }, out status);
        }
コード例 #2
0
        public string RunCommand()
        {
            IBitlyService bitlyService = new BitlyService("vhytyk", "R_5d31d4dc7a364cf6af291c7533655e55");

            string result = null;

            if (!string.IsNullOrEmpty(_searchPhrase))
            {
                var wikiService = new ConfluenceSoapServiceService();
                if (null == wikiToken)
                {
                    wikiToken = wikiService.login("vhytyk", "");
                }

                var resultList = new List <string>();
                var searchList = wikiService.search(wikiToken, _searchPhrase, 20)
                                 .Where(r => r.type == "page")
                                 .Take(3)
                                 .ToList();

                searchList.ForEach(s =>
                {
                    resultList.Add(string.Format("{1} ({0})",
                                                 bitlyService.Shorten(s.url.Replace("wiki/", "wiki.justanswer.local/")), s.title));
                });



                result = string.Join("\r", resultList);
            }

            return(result);
        }
コード例 #3
0
        public async Task Shorten()
        {
            var longUrl = "http://google.com.br/";

            var result = await _bitlyService.Shorten(longUrl);

            Assert.Equal(200, result.StatusCode);
            Assert.Equal("OK", result.Status);
            Assert.Equal(longUrl, result?.Data?.LongUrl);
        }
コード例 #4
0
        public string BitylFromApi(string url)
        {
            IBitlyService s = new BitlyService(userName, password);

            if (s.Shorten(url, out shortUrl) == StatusCode.OK)
            {
                Console.WriteLine(shortUrl);
                Console.ReadKey();
            }

            return(shortUrl);
        }
コード例 #5
0
        public string ShortenAndAddTagToUrl(string url)
        {
            var uriBuilder = new UriBuilder(url);
            var query      = HttpUtility.ParseQueryString(uriBuilder.Query);

            query["tag"] = Constants.Amazon.AssociateTag;

            uriBuilder.Query = query.ToString();

            //Can validate the link
            //https://affiliate-program.amazon.com/home/tools/linkchecker
            var endUrl = uriBuilder.ToString();

            var shortedEndUrl = "";

            if (Uri.IsWellFormedUriString(endUrl, UriKind.Absolute))
            {
                shortedEndUrl = _bitlyService.Shorten(endUrl);
            }

            return(shortedEndUrl);
        }
コード例 #6
0
        private static string GetBitlyUrl(ISettings settingsRepository, string url, string urlFormat)
        {
            var bitlyUsername = ApplicationConfiguration.BitlyUserName;
            var bitlyApiKey   = ApplicationConfiguration.BitlyApiKey;

            if (string.IsNullOrEmpty(bitlyUsername) || string.IsNullOrEmpty(bitlyApiKey))
            {
                return(null);
            }

            try
            {
                var    bitlyService = new BitlyService(bitlyUsername, bitlyApiKey);
                string shortUrl;
                bitlyService.Shorten(string.Format(urlFormat, settingsRepository.BlogAkismetUrl, url), out shortUrl);
                return(shortUrl);
            }
            catch
            {
                return(null);
            }
        }
コード例 #7
0
        public string Url(string url)
        {
            var status = _client.Shorten(url, out var shortened);

            return(status == StatusCode.OK ? shortened : url);
        }
コード例 #8
0
ファイル: Global.asax.cs プロジェクト: jacizd/Interntipset
        public static void SendTweet(string tweet, string appendUrl, SessionProperties sessionProperties)
        {
            if (TwitterService == null)
            {
                InitiateTwitterAuthentication(sessionProperties);
            }


            if (TwitterService == null)
            {
                WebControlManager.SendAndLogErrorMessage(new Exception("TwitterService not initialized"), Parameters.Instance.MailSender, Parameters.Instance.SupportMail);
                //clear authentication, guess we need to authenticate again?
                Parameters.Instance.TwitterAccessToken       = null;
                Parameters.Instance.TwitterAccessTokenSecret = null;
                return;
            }

            try
            {
                //format the string, replace
                if (tweet.Contains("&"))
                {
                    tweet = HttpUtility.HtmlDecode(tweet);
                }

                string shortUrl = String.Empty;
                //parse url to shorturl
                if (!String.IsNullOrEmpty(appendUrl))
                {
                    IBitlyService s = new BitlyService("o_3cpfcndji4", "R_8e203358cb5ca0f68d809419b056b192");

                    string shortened = s.Shorten(appendUrl);
                    if (shortened != null)
                    {
                        shortUrl = " " + shortened;
                    }
                }
                var maxLength = 140 - shortUrl.Length;
                if (tweet.Length > maxLength)
                {
                    tweet = tweet.Substring(0, maxLength);
                }

                tweet += shortUrl;

                TwitterService.SendTweet(new SendTweetOptions()
                {
                    Status = tweet
                });

                // Likely this is an error; we don't have to go fishing for it
                TwitterError    error    = TwitterService.Response.Error;
                TwitterResponse response = TwitterService.Response;
                if (error != null || response.StatusCode != HttpStatusCode.OK)
                {
                    // You now know you have a real error from Twitter, and can handle it
                    string message;
                    if (error != null)
                    {
                        message = String.Format("Twitter error: {0} ({1})", error.Message, error.Code);
                    }
                    else
                    {
                        message = String.Format("Twitter response status not ok: {0} ({1})\n{2}",
                                                response.StatusDescription, response.StatusCode, response.Response);
                    }
                    WebControlManager.SendAndLogErrorMessage(new Exception(message), Parameters.Instance.MailSender, Parameters.Instance.SupportMail);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }