【发布时间】:2016-08-17 03:29:43
【问题描述】:
我正在尝试学习 tweetinvi 凭证,所以我有以下 UI
还有这两种方法,initAuthentication 和 startAuthentication
private void initAuthentication()
{
var appCredentials = new TwitterCredentials(consumerKey, consumerSecret);
var authenticationContext = AuthFlow.InitAuthentication(appCredentials);
Process.Start(authenticationContext.AuthorizationURL);
//i am commenting the following code
//var userCredentials = AuthFlow.CreateCredentialsFromVerifierCode(textBox1.Text, authenticationContext);
//Auth.SetCredentials(userCredentials);
//so the user have some time to copy the pinCode
//paste them into available textbox
// and continue executing startAuthentication() by clicking authenticate button.
}
private void startAuthentication (string pinCode)
{
//if we split like this, the authenticationContext is error, because it doesn't exist in current context
var userCredentials = AuthFlow.CreateCredentialsFromVerifierCode(pinCode, authenticationContext);
Auth.SetCredentials(userCredentials);
}
如果我们将这两个部分加入一个功能,用户就没有时间将密码复制粘贴到文本框中。
但是,如果我们将这两个部分拆分为不同的功能,则用户需要一些时间将 pin 码复制粘贴到文本框中,但 authenticationContext 似乎出错了,因为 it doesn't exist in current context
有什么办法可以解决这个问题吗?
【问题讨论】:
-
你只能在本地范围内使用 var 而不是在全球范围内
-
@MostafizurRahman 同意,但是如何绕过或使我的代码按预期工作?
-
您想让对话框成为模态,然后在按下验证按钮之前它不会返回到应用程序。
-
大家好,我是 tweetinvi 的开发者。我可以说这两个答案都是正确的。有很多方法可以做你想做的事,但最简单的一种是将变量存储在私有属性中。