Authentication with Embedded Credentials

May 12, 2015 at 4:16 PM
The documentation suggests one can manually set all the credentials like this:
TwitterCredentials.SetCredentials(
    AccessToken,
    AccessTokenSecret,
    ConsumerKey,
    ConsumerSecret);
This is perfect for me because I am only trying to do things on behalf of my own Twitter account and therefore I can easily find the Access Token and Secret and embed them in my application. However, setting them in this fashion never seems to work. Is there any way to sign in on behalf of my own account without using a callback or CAPTCHA (i.e. without needing user interaction)? I'm just trying to run a Windows Service on behalf of my own account.
Coordinator
May 12, 2015 at 5:55 PM
This code should definitely work. It is the default solution to set credentials.

Could you please share more code.

Linvi
May 12, 2015 at 7:23 PM
Most certainly. Check out this simple example which does not work for me:
using System;
using Tweetinvi;
using Tweetinvi.Core.Interfaces.WebLogic;

namespace MyApp
{
    class Program
    {
        private static string AccessToken = "removed for security";
        private static string AccessTokenSecret = "removed for security";
        private static string ConsumerKey = "removed for security";
        private static string ConsumerSecret = "removed for security";

        static void Main(string[] args)
        {
            try
            {
                TwitterCredentials.SetCredentials(AccessToken, AccessTokenSecret, ConsumerKey, ConsumerSecret);
                
                var tweet = Tweet.PublishTweet("Test.");

                if (tweet == null)
                {
                    Console.WriteLine("Error tweeting:");
                    Console.WriteLine(ExceptionHandler.GetLastException().TwitterDescription);
                }
                else
                {
                    Console.WriteLine("Tweeted.");
                    Console.WriteLine(tweet.Text);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.ReadKey();
        }
    }
}
This results in the output:
Error tweeting:
Unauthorized - Authentication credentials were missing or incorrect.
May 12, 2015 at 9:28 PM
Never mind, I figured it out. It was a dumb thing that was my own fault. Thanks!
Marked as answer by linvi on 5/12/2015 at 4:02 PM