OAuth with TweetSharp for Windows Phone 7.1 : problem during the authentication


#1

Hello !

I use TweetSharp for WP7.1 and I have a problem during the Authentication.

In my page Connexion.xaml there is a WebBrowser Control, a TextBox named Pin and the button Connect.

service, Request and Access are declared in App.xaml.cs respectively as a TwitterService, an OAuthRequestToken and an OAuthAccessToken.

Code of Connexion.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using TweetSharp;

namespace CeCertainMoment
{
    public partial class Connexion : PhoneApplicationPage
    {
        public Connexion()
        {
            InitializeComponent();
            //Ask the Token and display the Twitter web page for the authorization
            App.service.GetRequestToken((request, Response) =>
            {
                if (Response.StatusCode == HttpStatusCode.OK)
                {
                    App.Request = request;
                    Uri uri = App.service.GetAuthorizationUri(request);
                    System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                        { LoginBrowser.Navigate(uri); });
                }
            });
        }

        private void Connect_Click(object sender, RoutedEventArgs e)
        {
            //Verify the entry of the user
            App.service.GetAccessToken(App.Request, Pin.Text, (access, Response) =>
            {
                if (Response.StatusCode == HttpStatusCode.OK)
                {
                    App.Access = access;
                    System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                        { NavigationService.Navigate(new Uri("/Composition.xaml", UriKind.Relative)); });
                }
            });
        }
    }
}

I don’t know if the problem is in GetRequestToken or in the GetAccessToken :

  • when I put a wrong Pin number, nothing happens.
  • when I put a empty or the right Pin number, I’m redirected to Composition.xaml and if I try to Tweet I have a NullReferenceException on the AuthenticateWith method.

Code of Composition.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using TweetSharp;

namespace CeCertainMoment
{
    public partial class Composition : PhoneApplicationPage
    {
        public Composition()
        {
            InitializeComponent();
        }

        private void Envoi_Click(object sender, RoutedEventArgs e)
        {
            App.service.AuthenticateWith(App.Access.Token, App.Access.TokenSecret);
            App.service.SendTweet((Intro.Text + tweet.Text), (Status, Response) =>
            {
                if (Response.StatusCode == HttpStatusCode.OK)
                {
                    MessageBox.Show("Tweet Sent !");
                }
            });
        }
    }
}

I’m a little lost with this NullReferenceException because during the initialisation of the application, in App.xaml.cs, I initialize service, Request and Access.

Thanks for your help !


#2

I’m having the same issue, as fas as I know, it is due to a recent update from Twitter (see https://dev.twitter.com/blog/ssl-upgrade-for-twitterapi).

I also tried with the LinqToTwitter lib, and the pin’s code validation doesn’t work anymore too.

It seems that you have to wait the creators of these libs update them.


#3

Indonesia. ,,,,,