VB.Net Authorization

Sep 3, 2013 at 6:18 PM
Edited Sep 3, 2013 at 9:21 PM
Mr. Mayo,

You have an "fixed" way of getting the PIN from the user currently (auto-opening browser via Start process). I have tried a number of ways around this with your sample code and the various object properties, but I am failing.
 Dim auth As PinAuthorizer = New PinAuthorizer()
 auth.Credentials = credentials
 auth.GetPin = AddressOf VerifierCallback
 auth.GoToTwitterAuthorization = Function(pageLink) Process.Start(pageLink)
 auth.Authorize()
How do I go about getting the authorization URL so I can display it in our apps built-in browser? We have it coded where the form displays the login in our own form and the user types in the PIN at the bottom of our window (we were previously using TwitterVB.DLL, but it no longer works).

Our structure previously when setting up new users in our application was to to take the user to the login window for Twitter, Twitter would give them the PIN, they would enter it in our window (textbox) and we would close window and continue on. I found your URL properties just fine, but I can't seem to figure out how to generate the correct token to go with the URL. That property is empty.

Please note, I have read through MANY discussions on this site and throughout the Googleverse. I did find this discussion (https://linqtotwitter.codeplex.com/discussions/431136) which is related to what I'm asking. I do not understand your reply. I've got a real mental block in understanding what parameters to pass to BeginAuthorization. Would you mind showing some basic VB.Net code to do this?

For what it's worth, I'm happy to pay or donate for assistance with this issue. Thanks.
Coordinator
Sep 4, 2013 at 7:21 PM
Edited Sep 4, 2013 at 7:21 PM
This post reminded me that I need to go out and ask for more help with writing demos - can't keep up with it myself. I don't have the exact demo that you need, but maybe the following (from a WP8 sample) will be more useful than the post you linked to.

This is on a page named OAuth.xaml, which includes a browser control and a TextBox that lets the user enter a PIN. The trick is to use the lambda/delegate assigned to GoToTwitterAuthorization to cause the browser control to navigate for you. After you set up the PinAuthorizer on the Page Load event, call BeginAuthorize. This will cause the lambda/delegate assigned to GoToTwitterAuthorization to execute, which navigates the browser to Twitter's authorization page, the URL specified by pageLink. The user will get a PIN, type it into the text box, and click a button to submit. Notice how the button event handler calls CompleteAuthorize, passing the PIN as the first parameter.
using System;
using System.Linq;
using System.Windows;
using System.Windows.Navigation;
using LinqToTwitter;
using Microsoft.Phone.Controls;

namespace UsersDemo
{
    public partial class OAuth : PhoneApplicationPage
    {
        PinAuthorizer pinAuth;

        public OAuth()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(Page_Loaded);
            OAuthWebBrowser.LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(OAuthWebBrowser_LoadCompleted);
        }

        void OAuthWebBrowser_LoadCompleted(object sender, NavigationEventArgs e)
        {
            EnterPinTextBlock.Visibility = Visibility.Visible;
            PinTextBox.IsEnabled = true;
            AuthenticateButton.IsEnabled = true;
        }

        void Page_Loaded(object sender, RoutedEventArgs e)
        {
            this.pinAuth = new PinAuthorizer
            {
                Credentials = new InMemoryCredentials
                {
                    ConsumerKey = "",
                    ConsumerSecret = ""
                },
                UseCompression = true,
                GoToTwitterAuthorization = pageLink =>
                    Dispatcher.BeginInvoke(() => OAuthWebBrowser.Navigate(new Uri(pageLink, UriKind.Absolute)))
            };

            this.pinAuth.BeginAuthorize(resp =>
                Dispatcher.BeginInvoke(() =>
                {
                    switch (resp.Status)
                    {
                        case TwitterErrorStatus.Success:
                            break;
                        case TwitterErrorStatus.TwitterApiError:
                        case TwitterErrorStatus.RequestProcessingException:
                            MessageBox.Show(
                                resp.Exception.ToString(),
                                resp.Message,
                                MessageBoxButton.OK);
                            break;
                    }
                }));
        }

        private void AuthenticateButton_Click(object sender, RoutedEventArgs e)
        {
            pinAuth.CompleteAuthorize(
                PinTextBox.Text,
                completeResp => Dispatcher.BeginInvoke(() =>
                {
                    switch (completeResp.Status)
                    {
                        case TwitterErrorStatus.Success:
                            SharedState.Authorizer = pinAuth;
                            NavigationService.GoBack();
                            break;
                        case TwitterErrorStatus.TwitterApiError:
                        case TwitterErrorStatus.RequestProcessingException:
                            MessageBox.Show(
                                completeResp.Exception.ToString(),
                                completeResp.Message,
                                MessageBoxButton.OK);
                            break;
                    }
                }));
        }
    }
}
@JoeMayo