Example #1
0
        XDocument Api(string method, Uri uri)
        {
            if (_tokens == null)
            {
                using (var repo = new Repo()) {
                    _tokens = repo.Table <TwitterOAuthTokens>().Where(t => t.Account == Account).FirstOrDefault();
                }
            }

            if (_tokens == null)
            {
                throw new InvalidOperationException("Cannot access Twitter APIs without tokens");
            }

            var wc = new WebClient();

            OAuthAuthorizer.AuthorizeRequest(OAuthConfig, wc, _tokens.Token, _tokens.TokenSecret, method, uri, "");

            var res = "";

            if (method == "GET")
            {
                res = wc.DownloadString(uri);
            }
            else
            {
                res = wc.UploadString(uri, "");
            }

            return(XDocument.Parse(res));
        }
Example #2
0
        void SaveAccessTokens()
        {
            using (var repo = new Repo()) {
                var tokens = repo.Table <TwitterOAuthTokens>().Where(t => t.Account == _auth.ScreenName).FirstOrDefault();

                if (tokens == null)
                {
                    tokens = new TwitterOAuthTokens()
                    {
                        Account     = _auth.ScreenName,
                        Token       = _auth.AccessToken,
                        TokenSecret = _auth.AccessTokenSecret,
                        UserId      = _auth.UserId
                    };
                    repo.Insert(tokens);
                }
                else
                {
                    tokens.Token       = _auth.AccessToken;
                    tokens.TokenSecret = _auth.AccessTokenSecret;
                    tokens.UserId      = _auth.UserId;
                    repo.Update(tokens);
                }
            }
        }
Example #3
0
        void SaveAccessTokens()
        {
            using (var repo = new Repo()) {

                var tokens = repo.Table<TwitterOAuthTokens>().Where(t => t.Account == _auth.ScreenName).FirstOrDefault();

                if (tokens == null) {
                    tokens = new TwitterOAuthTokens() {
                        Account = _auth.ScreenName,
                        Token = _auth.AccessToken,
                        TokenSecret = _auth.AccessTokenSecret,
                        UserId = _auth.UserId
                    };
                    repo.Insert(tokens);
                }
                else {
                    tokens.Token = _auth.AccessToken;
                    tokens.TokenSecret = _auth.AccessTokenSecret;
                    tokens.UserId = _auth.UserId;
                    repo.Update(tokens);
                }
            }
        }
Example #4
0
        XDocument Api(string method, Uri uri)
        {
            if (_tokens == null) {
                using (var repo = new Repo()) {
                    _tokens = repo.Table<TwitterOAuthTokens>().Where(t=>t.Account == Account).FirstOrDefault();
                }
            }

            if (_tokens == null) {
                throw new InvalidOperationException("Cannot access Twitter APIs without tokens");
            }

            var wc = new WebClient();

            OAuthAuthorizer.AuthorizeRequest(OAuthConfig, wc, _tokens.Token, _tokens.TokenSecret, method, uri, "");

            var res = "";

            if (method == "GET") {
                res = wc.DownloadString(uri);
            }
            else {
                res = wc.UploadString(uri, "");
            }

            return XDocument.Parse(res);
        }