OSDN Git Service

bit.ly 短縮機能実装のプライバシー問題の暫定対応
authorKimura Youichi <kim.upsilon@bucyou.net>
Thu, 29 Mar 2012 14:26:40 +0000 (23:26 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Thu, 29 Mar 2012 14:27:15 +0000 (23:27 +0900)
当面の間はAPIキーの指定を必須とし、指定されていない場合はbit.lyによって短縮されない (t.coによって短縮される)
参照: http://sourceforge.jp/projects/opentween/lists/archive/dev/2012-January/000020.html

OpenTween/AppendSettingDialog.cs
OpenTween/ShortUrl.cs

index 7d26f96..a596658 100644 (file)
@@ -113,14 +113,27 @@ namespace OpenTween
         private void Save_Click(object sender, EventArgs e)
         {
             if (MyCommon.IsNetworkAvailable() &&
-                (ComboBoxAutoShortUrlFirst.SelectedIndex == (int)MyCommon.UrlConverter.Bitly || ComboBoxAutoShortUrlFirst.SelectedIndex == (int)MyCommon.UrlConverter.Jmp) &&
-                 (!string.IsNullOrEmpty(TextBitlyId.Text) || !string.IsNullOrEmpty(TextBitlyPw.Text)))
+                (ComboBoxAutoShortUrlFirst.SelectedIndex == (int)MyCommon.UrlConverter.Bitly || ComboBoxAutoShortUrlFirst.SelectedIndex == (int)MyCommon.UrlConverter.Jmp))
             {
+                // bit.ly 短縮機能実装のプライバシー問題の暫定対応
+                // bit.ly 使用時はログインIDとAPIキーの指定を必須とする
+                // 参照: http://sourceforge.jp/projects/opentween/lists/archive/dev/2012-January/000020.html
+                if (string.IsNullOrEmpty(TextBitlyId.Text) || string.IsNullOrEmpty(TextBitlyPw.Text))
+                {
+                    MessageBox.Show("bit.ly のログイン名とAPIキーの指定は必須項目です。", Application.ProductName);
+                    _ValidationError = true;
+                    TreeViewSetting.SelectedNode = TreeViewSetting.Nodes["ConnectionNode"].Nodes["ShortUrlNode"]; // 動作タブを選択
+                    TreeViewSetting.Select();
+                    TextBitlyId.Focus();
+                    return;
+                }
+
                 if (!BitlyValidation(TextBitlyId.Text, TextBitlyPw.Text))
                 {
                     MessageBox.Show(Properties.Resources.SettingSave_ClickText1);
                     _ValidationError = true;
-                    TreeViewSetting.SelectedNode.Name = "TweetActNode"; // 動作タブを選択
+                    TreeViewSetting.SelectedNode = TreeViewSetting.Nodes["ConnectionNode"].Nodes["ShortUrlNode"]; // 動作タブを選択
+                    TreeViewSetting.Select();
                     TextBitlyId.Focus();
                     return;
                 }
@@ -1960,8 +1973,8 @@ namespace OpenTween
             string content = "";
             Dictionary<string, string> param = new Dictionary<string, string>();
 
-            param.Add("login", "tweenapi");
-            param.Add("apiKey", "R_c5ee0e30bdfff88723c4457cc331886b");
+            param.Add("login", ApplicationSettings.BitlyLoginId);
+            param.Add("apiKey", ApplicationSettings.BitlyApiKey);
             param.Add("x_login", id);
             param.Add("x_apiKey", apikey);
             param.Add("format", "txt");
index aefaf0f..7aafc6c 100644 (file)
@@ -330,13 +330,20 @@ namespace OpenTween
                             content = src;
                             break;
                         }
+                        if (string.IsNullOrEmpty(_bitlyId) || string.IsNullOrEmpty(_bitlyKey))
+                        {
+                            // bit.ly 短縮機能実装のプライバシー問題の暫定対応
+                            // ログインIDとAPIキーが指定されていない場合は短縮せずにPOSTする
+                            // 参照: http://sourceforge.jp/projects/opentween/lists/archive/dev/2012-January/000020.html
+                            content = src;
+                            break;
+                        }
                         string req = "";
                         req = "http://api.bitly.com/v" + BitlyApiVersion + "/shorten?";
-                        req += "login=" + ApplicationSettings.BitlyLoginId +
-                            "&apiKey=" + ApplicationSettings.BitlyApiKey +
+                        req += "login=" + _bitlyId +
+                            "&apiKey=" + _bitlyKey +
                             "&format=txt" +
                             "&longUrl=" + SrcUrl;
-                        if (!string.IsNullOrEmpty(_bitlyId) && !string.IsNullOrEmpty(_bitlyKey)) req += "&x_login=" + _bitlyId + "&x_apiKey=" + _bitlyKey;
                         if (ConverterType == MyCommon.UrlConverter.Jmp) req += "&domain=j.mp";
                         if (!(new HttpVarious()).GetData(req, null, out content))
                         {