예제 #1
0
        string TweetSync(string tweet)
        {
            IAsyncResult result = service.BeginSendTweet(
                new SendTweetOptions()
            {
                Status = tweet
            });

            TwitterStatus ts = service.EndSendTweet(result);

            if (ts == null)
            {
                throw new Exception("Error sending tweet");
            }

            return($"https://twitter.com/{ts.User.ScreenName}/status/{ts.Id}");
        }
예제 #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!editMode)
            {
                TwitterService service = new TwitterService("9fHcTGpQkdy25gAQ8bFmiOd67", "KBWAa7reZWDEofMkgDluIfLVk9dEaAZAOTinUFInw5k6xNGCX6");

                // Step 1 - Retrieve an OAuth Request Token
                OAuthRequestToken requestToken = service.GetRequestToken();

                // Step 2 - Redirect to the OAuth Authorization URL
                Uri uri = service.GetAuthorizationUri(requestToken);
                Process.Start(uri.ToString());

                // Step 3 - Exchange the Request Token for an Access Token
                string           verifier = "0350060"; // <-- This is input into your application by your user
                OAuthAccessToken access   = service.GetAccessToken(requestToken, verifier);

                // Step 4 - User authenticates using the Access Token
                service.AuthenticateWith(access.Token, access.TokenSecret);

                var aluno = new Aluno((Turma)Enum.Parse(typeof(Turma), cbxTurma.Text),
                                      txtNome.Text,
                                      txtSobrenome.Text,
                                      int.Parse(txtIdade.Text),
                                      double.Parse(txtNota.Text),
                                      (Status)Enum.Parse(typeof(Status), cbxStatus.Text));
                _alunoAplicacao.Adicionar(aluno);

                service.BeginSendTweet(new SendTweetOptions());
            }

            else
            {
                var aluno = _alunoAplicacao.Buscar(_aluno.Id);
                aluno.Turma     = (Turma)Enum.Parse(typeof(Turma), cbxTurma.Text);
                aluno.Nome      = txtNome.Text;
                aluno.Sobrenome = txtSobrenome.Text;
                aluno.Idade     = int.Parse(txtIdade.Text);
                aluno.Nota      = double.Parse(txtNota.Text);
                aluno.Status    = (Status)Enum.Parse(typeof(Status), cbxStatus.Text);
                _alunoAplicacao.Atualizar(aluno);
            }
            Close();
        }
        private bool Tweet(string textMsg, string filePath)
        {
            try
            {
                var _consumerKey       = "sKYbEuMWcgHVstzMNI2LOGzPP";                          // "rbZAEqnJlTuOALvQuJVwTv4Gr";
                var _consumerSecret    = "JOGniXtq1ozm4x5Kg5HpaJKw4TCpuKcD7RNFVIGuGfda9sZFWN"; //"8aKU3z8WfuZocaBsQx50sw16fgnptX3nGzNnPLluge2fF8sITk";
                var _accessToken       = "3244195770-fBcXK8QFz7zQSyNyfq6YkLYrtl8l16Q0bIiA9Sr"; //"21481943-ugmojCmL3nd3lX9IM5elidGBpxqREifI5FJSDFXRW";
                var _accessTokenSecret = "J2JQqupHCZOHYdD2TU6bMrh2yiIFYD2YdIaQFcCw48uv4";      //"r5neeSY6xM5JZsEQwxJgIn6bBxAvMLepIm73zF15ze6wq";

                var service = new TwitterService(_consumerKey, _consumerSecret);
                service.AuthenticateWith(_accessToken, _accessTokenSecret);

                TwitterStatus twitterStatus;

                if (!string.IsNullOrWhiteSpace(filePath))
                {
                    var dicImages = new Dictionary <string, Stream>();

                    dicImages.Add("temp", new FileStream(filePath, FileMode.Open));

                    var twitterTask = service.BeginSendTweetWithMedia(new SendTweetWithMediaOptions
                    {
                        Status = textMsg,
                        Images = dicImages
                    });
                    twitterStatus = service.EndSendTweetWithMedia(twitterTask);
                }
                else
                {
                    var twitterTask = service.BeginSendTweet(new SendTweetOptions
                    {
                        Status = textMsg,
                    });
                    twitterStatus = service.EndSendTweet(twitterTask);
                }

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
예제 #4
0
        public bool PublishToTwitter(string post, byte[] imageBytes)
        {
            try
            {
                var service = new TwitterService(Properties.Settings.Default.TwitterConsumerId, Properties.Settings.Default.TwitterConsumerSecret);
                service.AuthenticateWith(Properties.Settings.Default.TwitterToken, Properties.Settings.Default.TwitterTokenSecret);

                if (imageBytes != null && imageBytes.Length > 0)
                {
                    Image  postImage = Image.FromStream(new MemoryStream(imageBytes));
                    string fileName  = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + @"\" + DateTime.Now.ToString("ddMMyyyyhhmmss") + ".jpg";

                    postImage.Save(fileName);

                    Dictionary <string, Stream> dic = new Dictionary <string, Stream>();

                    FileStream ms = new FileStream(fileName, FileMode.Open);

                    dic.Add("", ms);
                    service.BeginSendTweetWithMedia(new SendTweetWithMediaOptions()
                    {
                        Status = post, Images = dic
                    });
                }
                else
                {
                    service.BeginSendTweet(new SendTweetOptions()
                    {
                        Status = post
                    });
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }