【问题标题】:Xamarin Android Xamarin.Auth - TwitterXamarin Android Xamarin.Auth - 推特
【发布时间】:2015-07-13 08:48:48
【问题描述】:

我在 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");
            }
        };
    }

希望有人能帮忙。

【问题讨论】:

    标签: xamarin xamarin.android


    【解决方案1】:

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

    callbackUrl: new Uri("http://mobile.twitter.com")
    

    之后就可以获得token了。

    希望它对将来的某人有所帮助。 :)

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

    【讨论】:

    • 非常感谢!! :)
    • 只是一个快速更新,他们现在重定向到这个地址:mobile.twitter.com/home 所以你现在需要使用这个作为回调。
    • 嗨。我使用它,我得到身份验证错误异常(删除服务器返回错误:(403)禁止。我该如何解决这个问题?
    【解决方案2】:

    我认为您需要将 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));
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-07
      • 1970-01-01
      • 1970-01-01
      • 2018-03-08
      • 2014-12-13
      • 1970-01-01
      • 1970-01-01
      • 2015-11-26
      相关资源
      最近更新 更多