0

Im having the following problem connecting to Twitter using OAuth PIN authorizer method.

The Code:

private async void button1_Click(object sender, RoutedEventArgs e)
    {
        pinAuth = new PinAuthorizer
        {

            CredentialStore = new InMemoryCredentialStore
            {

                ConsumerKey = resourceLoader.GetString("ConsumerKey"),
                ConsumerSecret = resourceLoader.GetString("ConsumerSecret")
            },

            GoToTwitterAuthorization = async pageLink =>
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
               () =>{ OAuthWebBrowser.Navigate(new Uri(pageLink, UriKind.Absolute)); })

        };
        await pinAuth.BeginAuthorizeAsync();

After retrieving the PIN I would do something like that:

private async void button2_Click(object sender, RoutedEventArgs e)
    {
        string pin = null; // Cant get the PIN
        await pinAuth.CompleteAuthorizeAsync(pin);

        var credentials = pinAuth.CredentialStore;
        string oauthToken = credentials.OAuthToken;
        string oauthTokenSecret = credentials.OAuthTokenSecret;
        string screenName = credentials.ScreenName;
        ulong userID = credentials.UserID;
    }

The browser opens I put my credentials into the form and click authorize. After this click the PIN pops up for half a second and then the following error message appears: "This page requires some information that was not provided. Please return to the site that sent you to this page and try again... it was probably an honest mistake"

Same problem in this Thread without solution so far.

Thank you!

//UPDATE

enter image description here

Ulpin
  • 179
  • 1
  • 14
  • http://stackoverflow.com/questions/16667361/linq-to-twitter-status-update This answer has the LinqToTwitter code to achieve this. The first part is for the old version if the library, but below that is an update with how to do it for the new version. –  Jun 06 '16 at 08:40

1 Answers1

1

With no response in soon 3 days I allow myself to give you an alternative example with Tweetinvi (which I am the developer). I understand that you are trying to use LinqToTwitter and I don't know the library enough to help you with this specific problem.

You can find more information regarding authentication in the associated wiki section.

// Create a new set of credentials for the application.
var appCredentials = new TwitterCredentials("CONSUMER_KEY", "CONSUMER_SECRET");

// Init the authentication process and store the related `AuthenticationContext`.
var authenticationContext = AuthFlow.InitAuthentication(appCredentials);

// Go to the URL so that Twitter authenticates the user and gives him a PIN code.
Process.Start(authenticationContext.AuthorizationURL);

// Ask the user to enter the pin code given by Twitter
var pinCode = Console.ReadLine();

// With this pin code it is now possible to get the credentials back from Twitter
var userCredentials = AuthFlow.CreateCredentialsFromVerifierCode(pinCode, authenticationContext);

// Use the user credentials in your application
Auth.SetCredentials(userCredentials);

I hope this could be of any help for you.

Linvi
  • 2,077
  • 1
  • 14
  • 28
  • Just to be clear before trying your idea... Is it possible to get the Twitter Conection over Tweetinvi and use it then with LinqToTwitter, or is this a real stupid question :-)? I am pretty far developing this application and I would have to redo all Twitter functionalties... – Ulpin Apr 21 '16 at 12:06
  • Yes it will be possible. The `userCredentials` coming from Tweetinvi will contain all the information you need to authentication with LinqToTwitter. – Linvi Apr 21 '16 at 12:30
  • `ITwitterCredentials` contain `access_token`, `access_token_secret`, `consumer_key` and finally `consumer_secret` which are all the information you need to authenticate. – Linvi Apr 21 '16 at 12:33
  • It produces the same error as LinqToTwitter does. var appCredentials = new TwitterCredentials(resourceLoader.GetString("ConsumerKey"), resourceLoader.GetString("ConsumerSecret")); var authenticationContext = AuthFlow.InitAuthentication(appCredentials); OAuthWebBrowser.Navigate(new Uri(authenticationContext.AuthorizationURL, UriKind.Absolute)); And see the image with the error message above – Ulpin Apr 21 '16 at 12:52
  • Could you share the URL in the `authenticationContext.AuthorizationURL` (you can alterate any private keys if they are shared in the url)? Also please let me know if the `Allow this application to be used to Sign in with Twitter` setting is enabled on your twitter app settings (https://apps.twitter.com/app//settings) – Linvi Apr 21 '16 at 13:04
  • This is the Url: `https://api.twitter.com/oauth/authorize?oauth_token=SdmZsQAAAAAAfJYrAAABVDj3bqU` and Yes, the checkbox to Sign in with Twitter is checked, – Ulpin Apr 21 '16 at 13:17
  • This looks perfectly correct. Are you sure that the `consumer_key` and `consumer_secret` are still valid. If they are (please distinguish consumer keys and access_token keys). Please try to regenerate them on the apps.twitter.com. – Linvi Apr 21 '16 at 13:44
  • Same thing again. I am able to log in with this account the entire time. But since I am using only single User authentication with all four connection parameters, this is clearly only for time of development - but it works. – Ulpin Apr 21 '16 at 13:54
  • Sorry I did not understand what you meant. Is it working or not? If this is still not working I would invite you to share more private information with me on gitter. I would be quite keen to understand what is causing this problem. https://gitter.im/linvi/tweetinvi – Linvi Apr 21 '16 at 13:59
  • Sry for beeing not clear. No, the PIn OAuth Authentification still doesn't work. I 've only wanted to tell you that I've could establish an single user authentication via linqToTwitter which shows valid Consumer key and Secret. – Ulpin Apr 21 '16 at 14:02
  • 1
    To make sure people visiting this page have a point to start to fix the problem, please make sure of the following: your environment has the datetime and timezone correctly set up. Make sure you try your solution on a real Windows Phone device. – Linvi Apr 21 '16 at 14:58