401 Unauthorized error when posting a status

Nov 8, 2014 at 12:12 PM
I'm getting a 401 Unauthorized error being thrown if i try to create a status containing the character '

Only getting the error the the status text contains that character.
Nov 8, 2014 at 12:27 PM
Edited Nov 8, 2014 at 4:11 PM
Replying to status also has the same affect.

Other characters such as ! also cause the same issue.
Coordinator
Nov 8, 2014 at 11:59 PM
Hi,

I just ran this on a Console app. I'm using .NET 4.5, Visual Studio 2013/Update 3, Windows 8.1, and LINQ to Twitter v3.1.0. What's the delta between what we're using?

@JoeMayo
Nov 9, 2014 at 12:09 AM
I'm using LINQ to Twitter v3.1.0, VS 2013 Update 3, Project is Universal WinRT.
Coordinator
Nov 9, 2014 at 2:30 AM
Edited Nov 9, 2014 at 2:37 AM
Thanks for that. I'm still not reproducing. Here's what I did:
  1. Create new universal app - Hub App and worked on the Windows Store project.
  2. Create a new class named SharedState, defined as follows:
    public class SharedState
    {
        public static IAuthorizer Authorizer { get; set; }
    }
  1. Open HubPage.xaml.cs and replace NavigationHelper_LoadState with:
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            // TODO: Create an appropriate data model for your problem domain to replace the sample data
            var sampleDataGroup = await SampleDataSource.GetGroupAsync("Group-4");
            this.DefaultViewModel["Section3Items"] = sampleDataGroup;

            if (SharedState.Authorizer == null)
            {
                var auth = new WindowsStoreAuthorizer
                {
                    CredentialStore = new InMemoryCredentialStore
                    {
                        ConsumerKey = "<your ApiKey>",
                        ConsumerSecret = "<your ApiSecret>"
                    },
                    Callback = "http://linqtotwitter.codeplex.com/"
                };

                await auth.AuthorizeAsync();

                SharedState.Authorizer = auth;
            }
        }
  1. Add a Button to ItemPage.xaml and replace it's handler, in ItemPage.xaml.cs, with this:
    async void Button_Click(object sender, RoutedEventArgs e)
    {
        var twitterCtx = new TwitterContext(SharedState.Authorizer);
    
        Status tweet = await twitterCtx.TweetAsync("Testing 'this'! - " + DateTime.Now.ToString());
    
        await new MessageDialog(tweet.Text, "Tweet Sent").ShowAsync();
    }
    
Note: this editor is encoding characters, but the tweet contains the characters you are having trouble with.

Are you able to do this?

@JoeMayo
Nov 9, 2014 at 11:49 AM
Edited Nov 9, 2014 at 11:58 AM
On further inspection i can confirm that WindowsStoreAuthorizer is not affected by this issue. At the moment it seems to be an issue with SingleUserAuthorizer.

HubPage.xaml.cs
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            // TODO: Create an appropriate data model for your problem domain to replace the sample data
            var sampleDataGroup = await SampleDataSource.GetGroupAsync("Group-4");
            this.DefaultViewModel["Section3Items"] = sampleDataGroup;

            if (SharedState.Authorizer == null)
            {
                var auth = new SingleUserAuthorizer
                {
                    CredentialStore =
                        new SingleUserInMemoryCredentialStore
                        {
                            ConsumerKey =
                                "",
                            ConsumerSecret =
                                "",
                            AccessToken =
                                "",
                            AccessTokenSecret =
                                ""
                        }
                };
                
                SharedState.Authorizer = auth;
            }
        }
Then the characters ' and ! are throwing the authorization error
Coordinator
Nov 12, 2014 at 2:55 AM
Edited Nov 12, 2014 at 2:56 AM
Tried that and still not reproducing:
    private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
    {
        // TODO: Create an appropriate data model for your problem domain to replace the sample data
        var sampleDataGroup = await SampleDataSource.GetGroupAsync("Group-4");
        this.DefaultViewModel["Section3Items"] = sampleDataGroup;

        //if (SharedState.Authorizer == null)
        //{
        //    var auth = new WindowsStoreAuthorizer
        //    {
        //        CredentialStore = new InMemoryCredentialStore
        //        {
        //            ConsumerKey = "",
        //            ConsumerSecret = ""
        //        },
        //        Callback = "http://linqtotwitter.codeplex.com/"
        //    };
            var auth = new SingleUserAuthorizer
            {
                CredentialStore =
                    new SingleUserInMemoryCredentialStore
                    {
                        ConsumerKey =
                            "",
                        ConsumerSecret =
                            "",
                        AccessToken =
                            "",
                        AccessTokenSecret =
                            ""
                    }
            };

            SharedState.Authorizer = auth;
        //}
    }
Are you sure there isn't something covered in the 401 FAQ affecting you?

https://linqtotwitter.codeplex.com/wikipage?title=LINQ%20to%20Twitter%20FAQ&referringTitle=Documentation

@JoeMayo
Nov 12, 2014 at 11:31 AM
Hi Joe,

I have gone through that FAQ and don't think anything should be affecting me. Could you try repo with this sample project? Need to enter credentials in HubPage.xaml.cs - NavigationHelper_LoadState

Linq2Twitter auth issue project

Thanks
Coordinator
Nov 12, 2014 at 2:20 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.