public void ShowConfigForm()
 {
     //check to see if they have already configured stuff. If so lets make sure they want to reconfigure settings.
     if (tweetManager.isConfigured)
     {
         reconfigConfirm = new WpfFormLibrary.ReconfigConfirm();
         reconfigConfirm.Closed += reconfigConfirm_Closed; // avoid reshowing a disposed form
         ElementHost.EnableModelessKeyboardInterop(reconfigConfirm);
         if (reconfigConfirm.ShowDialog() == false)
         {
             return;
         }
     }
     //Show config Form
     configForm = new WpfFormLibrary.ConfigForm();
     configForm.Closed += configForm_Closed; // avoid reshowing a disposed form
     ElementHost.EnableModelessKeyboardInterop(configForm);
     //check to make sure they didnt exit the prompt
     if (configForm.ShowDialog() == true)
     {
         tweetManager.isConfigured = true;
         this.OAuthManager = configForm.OAuthz;
         this.SID = configForm.SID;
         this.registeredTime = DateTime.Now.ToString("MM/dd/yy:HH:mm:ss");
         return;
     }
     else
         ShowConfigForm();
 }
Beispiel #2
0
        private FitBit()
        {
            Debug.Log("Making new Fitbit");
            manager = new OAuth.Manager();
            manager["consumer_key"]    = CONSUMER_KEY;
            manager["consumer_secret"] = CONSUMER_SECRET;
            authenticated    = false;
            isAuthenticating = false;
            string access_token;
            string access_secret;

            //if stored.
            if ((access_token = PlayerPrefs.GetString(TOKEN_KEY)) != "")
            {
                authenticated = true;
                access_secret = PlayerPrefs.GetString(TOKEN_SECRET_KEY);

                manager[TOKEN_KEY]        = access_token;
                manager[TOKEN_SECRET_KEY] = access_secret;
            } // if it has not made the call yet
            else if (PlayerPrefs.GetInt(AUTHENTICATING, 0) == 0)
            { // Need to verify. Launch browser.
                isAuthenticating = true;
                PlayerPrefs.SetInt(AUTHENTICATING, 1);
                PlayerPrefs.Save();
                getToken();
            }
        }
Beispiel #3
0
 public void ShowConfigForm()
 {
     //check to see if they have already configured stuff. If so lets make sure they want to reconfigure settings.
     if (tweetManager.isConfigured)
     {
         reconfigConfirm         = new WpfFormLibrary.ReconfigConfirm();
         reconfigConfirm.Closed += reconfigConfirm_Closed; // avoid reshowing a disposed form
         ElementHost.EnableModelessKeyboardInterop(reconfigConfirm);
         if (reconfigConfirm.ShowDialog() == false)
         {
             return;
         }
     }
     //Show config Form
     configForm         = new WpfFormLibrary.ConfigForm();
     configForm.Closed += configForm_Closed; // avoid reshowing a disposed form
     ElementHost.EnableModelessKeyboardInterop(configForm);
     //check to make sure they didnt exit the prompt
     if (configForm.ShowDialog() == true)
     {
         tweetManager.isConfigured = true;
         this.OAuthManager         = configForm.OAuthz;
         this.SID            = configForm.SID;
         this.registeredTime = DateTime.Now.ToString("MM/dd/yy:HH:mm:ss");
         return;
     }
     else
     {
         ShowConfigForm();
     }
 }
        public TwitterClient()
        {
            tweets = new ObservableCollection<AbridgedTweet>();
            httpClient = new HttpClient();
            oauthManager = new OAuth.Manager();

            LoggedIn = false;
            Status = "OK";

            // The consumer key and secret are specific to this app and were obtained by registration with Twitter.com
            oauthManager["consumer_key"] = "tUitLCoAeRPXTQ9QujmxMjvI2";
            oauthManager["consumer_secret"] = "lLvZNB4ihc5ZJJCWOB3X33ySMHwn5WJ0f0NmvH9gkNIkTTaD8W";

            // If we have previously authorized this app and still have our access token, use it
            if (System.IO.File.Exists("access_token.txt") && System.IO.File.Exists("access_token_secret.txt"))
            {
                oauthManager["token"] = System.IO.File.ReadAllText("access_token.txt");
                oauthManager["token_secret"] = System.IO.File.ReadAllText("access_token_secret.txt");

                if (VerifyCredentials())
                {
                    LoggedIn = true;

                    GetInitialTweets();
                }
            }
        }
Beispiel #5
0
        public TwitterClient()
        {
            tweets       = new ObservableCollection <AbridgedTweet>();
            httpClient   = new HttpClient();
            oauthManager = new OAuth.Manager();

            LoggedIn = false;
            Status   = "OK";

            // The consumer key and secret are specific to this app and were obtained by registration with Twitter.com
            oauthManager["consumer_key"]    = "tUitLCoAeRPXTQ9QujmxMjvI2";
            oauthManager["consumer_secret"] = "lLvZNB4ihc5ZJJCWOB3X33ySMHwn5WJ0f0NmvH9gkNIkTTaD8W";

            // If we have previously authorized this app and still have our access token, use it
            if (System.IO.File.Exists("access_token.txt") && System.IO.File.Exists("access_token_secret.txt"))
            {
                oauthManager["token"]        = System.IO.File.ReadAllText("access_token.txt");
                oauthManager["token_secret"] = System.IO.File.ReadAllText("access_token_secret.txt");

                if (VerifyCredentials())
                {
                    LoggedIn = true;

                    GetInitialTweets();
                }
            }
        }
        public string SendHttpRequest(string url, string stringifiedJsonData, string method)
        {
            var result = string.Empty;

            var oauth = new OAuth.Manager();

            oauth["consumer_key"]    = "43981534e855f4adca425575b4328a702ade9500a78447f2bff4dedcb3af753b";
            oauth["consumer_secret"] = "fea909450f17d77cb578c45f59d8829bcaf18cd649f9b5edd1d0af24506e5079";
            oauth["token"]           = "bc9728a02cceb69ed4d02e80e8bed8078526395affdd4c13108b7fcaeead58b1";
            oauth["token_secret"]    = "5f44e752e4af109cdb0208895382113d5dd6ab907b065b6100a80e5874089d59";
            var realm       = "5802100_SB1";
            var authzHeader = oauth.GenerateCredsHeader(url, "POST", realm);

            //发送请求
            var request = (HttpWebRequest)WebRequest.Create(url);
            var data    = Encoding.UTF8.GetBytes(stringifiedJsonData);

            request.Method                    = method;
            request.Timeout                   = -1;
            request.PreAuthenticate           = true;
            request.AllowWriteStreamBuffering = true;
            request.Headers.Add("Authorization", authzHeader);
            //request.Headers.Add("Authorization", "OAuth realm=\"5802100_SB1\",oauth_consumer_key=\"43981534e855f4adca425575b4328a702ade9500a78447f2bff4dedcb3af753b\",oauth_token=\"bc9728a02cceb69ed4d02e80e8bed8078526395affdd4c13108b7fcaeead58b1\",oauth_signature_method=\"HMAC-SHA256\",oauth_timestamp=\"1608088304\",oauth_nonce=\"kBbOOWvNAP9\",oauth_version=\"1.0\",oauth_signature=\"EWFZBikSMI5o2zlLg4f2LevqlipvUWnZ6s3B6Alg%2FDs%3D\"");
            //request.Headers.Add("Cookie", "lastUser=5802100_SB1_40_1016; NS_ROUTING_VERSION=LAGGING");

            request.ContentType = "application/json";
            request.KeepAlive   = false;
            request.ServicePoint.Expect100Continue = false;
            request.ContentLength = data.Length;
            request.Accept        = "application/json";
            ServicePointManager.DefaultConnectionLimit = 1000;      //提高每秒默认请求数量
            var headers = request.Headers.ToString();

            _logger.AddRequestLog(url, headers, stringifiedJsonData, null);

            using (var reqStream = request.GetRequestStream())
            {
                reqStream.Write(data, 0, data.Length);
                reqStream.Close();
            }

            try
            {
                var response = request.GetResponse();
                var stream   = response.GetResponseStream();
                //获取响应
                using (var reader = new StreamReader(stream, Encoding.UTF8))
                {
                    result = reader.ReadToEnd();
                }
            }
            catch (Exception e)
            {
                _logger.AddRequestLog(url, headers, stringifiedJsonData, e.Message);
                throw new Exception(e.Message);
            }

            return(result);
        }
Beispiel #7
0
        protected virtual OAuth.Manager GetOAuthManager()
        {
            var oauthManager = new OAuth.Manager(PremiarSettings.Authorization.ClientId.ToString(), PremiarSettings.Authorization.ClientSecret);

            oauthManager["subscription-key"] = PremiarSettings.Authorization.SubscriptionKey;
            oauthManager["campaign_id"]      = PremiarSettings.Credentials.CampaignId.ToString();
            return(oauthManager);
        }
Beispiel #8
0
        protected override OAuth.Manager GetOAuthManager()
        {
            var oauthManager = new OAuth.Manager(PremiarSettings.Authorization.ClientId.ToString(), PremiarSettings.Authorization.ClientSecret);

            oauthManager["subscription-key"] = PremiarSettings.Authorization.SubscriptionKey;
            oauthManager["campaign_id"]      = PremiarSettings.Credentials.CampaignId.ToString();
            oauthManager["username"]         = loggedUser.username;
            oauthManager["password"]         = loggedUser.password;
            return(oauthManager);
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            //you'll first need to provision a twitter client app for access: https://apps.twitter.com/
            //then plug in the following magic cookies from here: https://apps.twitter.com/app/{your_app_id}/keys
            var oauth = new OAuth.Manager
            {
                ["consumer_key"]    = "",
                ["consumer_secret"] = "",
                ["token"]           = "",
                ["token_secret"]    = ""
            };

            //here's the api docs: https://dev.twitter.com/rest/public
            //e.g. https://dev.twitter.com/rest/reference/get/followers/ids
            //they all have a nice OAuth "signature generator" at the bottom that will create a valid curl command line
            //i didn't have any success with the curl approach but "PostMan" plugin for Chrome worked right away

            //following example loops over all your followers and removes them

            var client = new WebClient();

            var yourScreenName = "";

            var url = $"https://api.twitter.com/1.1/followers/ids.json?screen_name={yourScreenName}";

            client.Headers["Authorization"] = oauth.GenerateAuthzHeader(url, "GET");
            var result = client.DownloadString(url);

            var jobj  = JObject.Parse(result);
            var value = jobj.GetValue("ids");
            var ids   = value.ToObject <string[]>();

            foreach (var id in ids)
            {
                //removing a follower translates to blocking them and then unblocking
                //block
                url = $"https://api.twitter.com/1.1/blocks/create.json?user_id={id}";
                client.Headers["Authorization"] = oauth.GenerateAuthzHeader(url, "POST");;
                result = client.UploadString(url, "");

                //then unblock
                url = $"https://api.twitter.com/1.1/blocks/destroy.json?user_id={id}";
                client.Headers["Authorization"] = oauth.GenerateAuthzHeader(url, "POST");;
                result = client.UploadString(url, "");
            }
        }
Beispiel #10
0
 public TwitPicOauthForm(OAuth.Manager oauth)
 {
     InitializeComponent();
     _oauth = oauth;
     GetRequestToken();
 }
Beispiel #11
0
 /// <summary>
 /// Initializes the oauth manager and acquires a request token if needed
 /// </summary>
 public static void InitOAuth()
 {
     oauth = new OAuth.Manager();
     oauth["consumer_key"] = oauth_key;
     oauth["consumer_secret"] = oauth_secret;
     if (Linked)
     {
         oauth["token"] = SettingsManager.OAuthToken;
         oauth["token_secret"] = SettingsManager.OAuthSecret;
         RetrieveUserData();
     }
     else
     {
         try
         {
             oauth.AcquireRequestToken(domain + "/oauth/request_token", "POST");
             oauth_request_token = oauth["token"];
         }
         catch (Exception e)
         {
             U.L(LogLevel.Warning, "SERVICE", "Problem linking with account: " + e.Message);
             Connected = false;
         }
     }
 }
Beispiel #12
0
 public TwitPicOauthForm(OAuth.Manager oauth)
 {
     InitializeComponent();
     _oauth= oauth;
     GetRequestToken();
 }
Beispiel #13
0
 public void InitializeManager(string consumerKey, string consumerSecret, string token, string tokenSecret)
 {
     OAuthManager = new OAuth.Manager(consumerKey, consumerSecret, token, tokenSecret);
 }