在我的Xamarin Android中实现twitter登录有问题。我已经包含了Xamarin.Auth组件,它对Facebook很好。对于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");
}
};
}我希望有人能帮忙。
发布于 2015-07-23 10:58:44
好的,我自己解决了这个问题。创建新OAuth1Authenticator时,CallBack Url应设置为mobile.twitter.com而不是twitter.com
callbackUrl: new Uri("http://mobile.twitter.com")在此之后,您将能够获得令牌。
希望它能对未来的人有所帮助。:)
编辑:你现在需要使用http://mobile.twitter.com/home -
发布于 2015-07-13 12:34:36
我认为您需要移动您的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));
}https://stackoverflow.com/questions/31379011
复制相似问题