Cannot send a Tweet

Oct 24, 2014 at 10:57 AM
Hi Linvi,

I've extended your example as below, but I never get a valid response when trying to send a Tweet. There don't seem t be any errors anywhere, is there any way to track down additional information as to where the problem may lie?

I've tried this both with and without the SetCredentials call.

Many thanks,
Russell
// Consumer Key and Secret are specific to your application, you can get these on apps.twitter.com
            var applicationCredentials = 
                CredentialsCreator.GenerateApplicationCredentials(oauth_consumer_key, oauth_consumer_secret);

            var url = CredentialsCreator.GetAuthorizationURL(applicationCredentials);

            // Open the URL to authenticate yourself on Twitter
            Process.Start(url);
            Console.WriteLine("Please enter the captcha : ");
            var captcha = Console.ReadLine();

            // Here are the new credentials!
            var result = CredentialsCreator.GetCredentialsFromVerifierCode(captcha, applicationCredentials);


            Console.WriteLine(result.AccessTokenSecret);


            //TwitterCredentials.SetCredentials(applicationCredentials.AuthorizationKey, result.AccessTokenSecret, oauth_consumer_key, oauth_consumer_secret);

                var tweet = Tweetinvi
                    .Tweet
                    .PublishTweet("test status " + Guid.NewGuid());


                Console.WriteLine(tweet != null);
Oct 24, 2014 at 11:38 AM
Hi,

I've hooked this up to your source code for the latest release.

Without setting the credentials, I can see the error telling me to set the credentials, so this is now done.

I re-ran the example above with the SetCredentials line uncommented, and eventually traced the problem to, yes, a 401 Not Authorised Exception.

So, I imagine I'm setting the wrong variable in the wrong place somewhere. If you have any suggestions as to where I could be going wrong that would be appreciated.

Many thanks.
Oct 24, 2014 at 11:46 AM
OK, cracked it, there is another Token being returned from the GetCredentialsFromVerifierCode, so I was using the new Secret with the old Token.

Final code below, phew
            // Consumer Key and Secret are specific to your application, you can get these on apps.twitter.com
            var applicationCredentials =
                CredentialsCreator.GenerateApplicationCredentials(oauth_consumer_key, oauth_consumer_secret);

            var url = CredentialsCreator.GetAuthorizationURL(applicationCredentials);

            // Open the URL to authenticate yourself on Twitter
            Process.Start(url);
            Console.WriteLine("Please enter the captcha : ");
            var captcha = Console.ReadLine();

            // Here are the new credentials!
            var result = CredentialsCreator.GetCredentialsFromVerifierCode(captcha, applicationCredentials);


            Console.WriteLine(result.AccessTokenSecret);


            TwitterCredentials
                .SetCredentials
                (
                    result.AccessToken,
                    result.AccessTokenSecret, 
                    oauth_consumer_key, 
                    oauth_consumer_secret
                );

            var tweet = 
                Tweetinvi
                .Tweet
                .PublishTweet("test status " + Guid.NewGuid());
Marked as answer by russellagnew on 10/24/2014 at 3:46 AM
Coordinator
Oct 24, 2014 at 2:49 PM
Just to let you know you can do :
var result = CredentialsCreator.GetCredentialsFromVerifierCode(captcha, applicationCredentials);
TwitterCredentials.SetCredentials(result );
Linvi