Xamarin Android Xamarin.Auth - 推特
Xamarin Android Xamarin.Auth - Twitter
我在 Xamarin Android 中实现 Twitter 登录时遇到问题。
我包含了 Xamarin.Auth 组件,它适用于 Facebook。
Fot twitter auth.Completed 事件未被调用...
我已经在 Twitter 开发门户上创建了示例应用程序。
这是我在应用程序中的代码:
private void LoginTwitter()
{
var auth = new OAuth1Authenticator(
consumerKey: "3v7rOXkdexGYhQmr3HVhtGgPO",
consumerSecret: "mGhRjee87tAp4X0vHUmMIohWoYy0JGg9zFGyin7CigFP64y3j5",
requestTokenUrl: new Uri("https://api.twitter.com/oauth/request_token"),
authorizeUrl: new Uri("https://api.twitter.com/oauth/authorize"),
accessTokenUrl: new Uri("https://api.twitter.com/oauth/access_token"),
callbackUrl: new Uri("http://twitter.com")
);
auth.AllowCancel = true;
StartActivity(auth.GetUI(this));
auth.Completed += (s, eventArgs) =>
{
if (eventArgs.IsAuthenticated)
{
Account loggedInAccount = eventArgs.Account;
//save the account data for a later session, according to Twitter docs, this doesn't expire
AccountStore.Create(this).Save(loggedInAccount, "Twitter");
}
};
}
希望有人帮忙
我认为您需要将 Completed
事件处理上移,因为我认为 StartActivity
正在阻塞。
private void LoginTwitter()
{
var auth = new OAuth1Authenticator(
consumerKey: "3v7rOXkdexGYhQmr3HVhtGgPO",
consumerSecret: "mGhRjee87tAp4X0vHUmMIohWoYy0JGg9zFGyin7CigFP64y3j5",
requestTokenUrl: new Uri("https://api.twitter.com/oauth/request_token"),
authorizeUrl: new Uri("https://api.twitter.com/oauth/authorize"),
accessTokenUrl: new Uri("https://api.twitter.com/oauth/access_token"),
callbackUrl: new Uri("http://twitter.com")
);
auth.AllowCancel = true;
auth.Completed += (s, eventArgs) =>
{
if (eventArgs.IsAuthenticated)
{
Account loggedInAccount = eventArgs.Account;
//save the account data for a later session, according to Twitter docs, this doesn't expire
AccountStore.Create(this).Save(loggedInAccount, "Twitter");
}
};
StartActivity(auth.GetUI(this));
}
好的,我自己解决了这个问题。
创建新的 OAuth1Authenticator 时
CallBack Url 应设置为 mobile.twitter.com 而不是 twitter.com
callbackUrl: new Uri("http://mobile.twitter.com")
之后您将能够获得令牌。
希望对以后的人有所帮助。 :)
编辑:您现在需要使用 http://mobile.twitter.com/home
-
我在 Xamarin Android 中实现 Twitter 登录时遇到问题。 我包含了 Xamarin.Auth 组件,它适用于 Facebook。 Fot twitter auth.Completed 事件未被调用... 我已经在 Twitter 开发门户上创建了示例应用程序。
这是我在应用程序中的代码:
private void LoginTwitter()
{
var auth = new OAuth1Authenticator(
consumerKey: "3v7rOXkdexGYhQmr3HVhtGgPO",
consumerSecret: "mGhRjee87tAp4X0vHUmMIohWoYy0JGg9zFGyin7CigFP64y3j5",
requestTokenUrl: new Uri("https://api.twitter.com/oauth/request_token"),
authorizeUrl: new Uri("https://api.twitter.com/oauth/authorize"),
accessTokenUrl: new Uri("https://api.twitter.com/oauth/access_token"),
callbackUrl: new Uri("http://twitter.com")
);
auth.AllowCancel = true;
StartActivity(auth.GetUI(this));
auth.Completed += (s, eventArgs) =>
{
if (eventArgs.IsAuthenticated)
{
Account loggedInAccount = eventArgs.Account;
//save the account data for a later session, according to Twitter docs, this doesn't expire
AccountStore.Create(this).Save(loggedInAccount, "Twitter");
}
};
}
希望有人帮忙
我认为您需要将 Completed
事件处理上移,因为我认为 StartActivity
正在阻塞。
private void LoginTwitter()
{
var auth = new OAuth1Authenticator(
consumerKey: "3v7rOXkdexGYhQmr3HVhtGgPO",
consumerSecret: "mGhRjee87tAp4X0vHUmMIohWoYy0JGg9zFGyin7CigFP64y3j5",
requestTokenUrl: new Uri("https://api.twitter.com/oauth/request_token"),
authorizeUrl: new Uri("https://api.twitter.com/oauth/authorize"),
accessTokenUrl: new Uri("https://api.twitter.com/oauth/access_token"),
callbackUrl: new Uri("http://twitter.com")
);
auth.AllowCancel = true;
auth.Completed += (s, eventArgs) =>
{
if (eventArgs.IsAuthenticated)
{
Account loggedInAccount = eventArgs.Account;
//save the account data for a later session, according to Twitter docs, this doesn't expire
AccountStore.Create(this).Save(loggedInAccount, "Twitter");
}
};
StartActivity(auth.GetUI(this));
}
好的,我自己解决了这个问题。 创建新的 OAuth1Authenticator 时 CallBack Url 应设置为 mobile.twitter.com 而不是 twitter.com
callbackUrl: new Uri("http://mobile.twitter.com")
之后您将能够获得令牌。
希望对以后的人有所帮助。 :)
编辑:您现在需要使用 http://mobile.twitter.com/home
-