首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xamarin.Auth - Twitter

Xamarin.Auth - Twitter
EN

Stack Overflow用户
提问于 2015-07-13 08:48:48
回答 2查看 2.1K关注 0票数 1

在我的Xamarin Android中实现twitter登录有问题。我已经包含了Xamarin.Auth组件,它对Facebook很好。对于twitter auth.Completed事件不叫..。我在twitter开发门户上创建了示例应用程序。

下面是我在应用程序中的代码:

代码语言:javascript
复制
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");
            }
        };
    }

我希望有人能帮忙。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-07-23 10:58:44

好的,我自己解决了这个问题。创建新OAuth1Authenticator时,CallBack Url应设置为mobile.twitter.com而不是twitter.com

代码语言:javascript
复制
callbackUrl: new Uri("http://mobile.twitter.com")

在此之后,您将能够获得令牌。

希望它能对未来的人有所帮助。:)

编辑:你现在需要使用http://mobile.twitter.com/home -

票数 7
EN

Stack Overflow用户

发布于 2015-07-13 12:34:36

我认为您需要移动您的Completed事件处理,因为我认为StartActivity阻塞了。

代码语言:javascript
复制
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));
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31379011

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档