c#LinqToTwitter连接OAuth PIN

时间:2016-04-18 19:13:51

标签: c# oauth windows-phone-8.1 linq-to-twitter

我使用OAuth PIN授权方法连接到Twitter时遇到以下问题。

守则:

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();

检索PIN后我会做类似的事情:

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;
    }

浏览器打开我将凭据放入表单并单击“授权”。在此之后单击PIN弹出半秒钟,然后出现以下错误消息: "此页面需要一些未提供的信息。请返回发送到此页面的网站,然后重试......这可能是一个诚实的错误"

到目前为止,这个Thread没有解决方案的问题相同。

谢谢!

// UPDATE

enter image description here

1 个答案:

答案 0 :(得分:0)

在3天内没有回应我允许自己给你一个Tweetinvi(我是开发人员)的另一个例子。我知道您正在尝试使用LinqToTwitter,而且我不太了解该库,可以帮助您解决这个特定问题。

您可以在相关的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);

我希望这对你有任何帮助。