Exemple #1
0
        public static bool GeoEnabled()
        {
            bool   result = false;
            string url    = "https://api.twitter.com/1.1/account/verify_credentials.json";

            Dictionary <string, string> headers = TwitterOAuth.getInstance().createOAuthHeader("GET", url, new Dictionary <string, string>());

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.ServicePoint.Expect100Continue = false;
            foreach (string key in headers.Keys)
            {
                request.Headers.Add(key, headers[key]);
            }
            request.Method  = WebRequestMethods.Http.Get;
            request.Timeout = 8000;
            if (Properties.Settings.Default.ProxyServer.Length > 0)
            {
                request.Proxy = new WebProxy(string.Format("http://{0}:{1}", Properties.Settings.Default.ProxyServer, Properties.Settings.Default.ProxyPort));
            }

            using (WebResponse response = request.GetResponse())
                using (JsonTextReader reader = new JsonTextReader(new StreamReader(response.GetResponseStream())))
                {
                    /*
                     * string r = reader.ReadToEnd();
                     * XmlDocument doc = new XmlDocument();
                     * doc.LoadXml(r);
                     * XmlNodeList list = doc.SelectNodes("/user/geo_enabled");
                     * if (list != null && list.Count > 0)
                     * {
                     *  XmlNode node = list[0];
                     *  result = bool.Parse(node.InnerText);
                     * }
                     */
                    while (reader.Read())
                    {
                        if (reader.Value != null)
                        {
                            if (reader.TokenType == JsonToken.PropertyName && reader.Value.ToString() == "geo_enabled")
                            {
                                reader.Read();
                                result = (Boolean)reader.Value;
                            }
                        }
                    }
                }
            return(result);
        }
Exemple #2
0
 private void btnXAuth_Click(object sender, EventArgs e)
 {
     Cursor.Current = Cursors.WaitCursor;
     try
     {
         Properties.Settings.Default.OAuthToken       = "";
         Properties.Settings.Default.OAuthTokenSecret = "";
         TwitterOAuth.getInstance().getAccessToken(txtTwitterID.Text, txtTwitterPassword.Text);
         MessageBox.Show("認証成功", "Twitter 認証", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "認証失敗", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     Cursor.Current = Cursors.Default;
 }
Exemple #3
0
        public static string Tweet(string status, GPSTrackPoint location)
        {
            string result;
            string url = "https://api.twitter.com/1.1/statuses/update.json";

            Dictionary <string, string> postData = new Dictionary <string, string>();

            //postData.Add("status", Util.URLEncode(status));
            postData.Add("status", status);
            if (Properties.Settings.Default.LocationTwit)
            {
                postData.Add("lat", Math.Round(location.Latitude, 6).ToString());
                postData.Add("long", Math.Round(location.Longitude, 6).ToString());
            }

            Dictionary <string, string> headers = TwitterOAuth.getInstance().createOAuthHeader("POST", url, postData);
            StringBuilder sb    = new StringBuilder();
            bool          first = true;

            foreach (string key in postData.Keys)
            {
                if (!first)
                {
                    sb.Append("&");
                }
                else
                {
                    first = false;
                }
                sb.Append(String.Format("{0}={1}", key, Util.URLEncode(postData[key])));
            }

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.ServicePoint.Expect100Continue = false;
            request.ContentType = "application/x-www-form-urlencoded";
            request.Method      = WebRequestMethods.Http.Post;
            request.Timeout     = 8000;
            foreach (string key in headers.Keys)
            {
                request.Headers.Add(key, headers[key]);
            }

            if (Properties.Settings.Default.ProxyServer.Length > 0)
            {
                request.Proxy = new WebProxy(string.Format("http://{0}:{1}", Properties.Settings.Default.ProxyServer, Properties.Settings.Default.ProxyPort));
            }

            byte[] bytes = Encoding.ASCII.GetBytes(sb.ToString());
            request.ContentLength = bytes.Length;
            using (Stream requestStream = request.GetRequestStream())
            {
                requestStream.Write(bytes, 0, bytes.Length);
            }

            using (WebResponse response = request.GetResponse())
            {
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    result = reader.ReadToEnd();
                }
            }
            return(result);
        }