Xamarin.Auth 与 Twitter [英] Xamarin.Auth with Twitter

查看:20
本文介绍了Xamarin.Auth 与 Twitter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Facebook 和 Twitter 实现登录.我在 Facebook 上得到了它,但不知道如何在 Twitter 上做到这一点.有没有例子?我的 Facebook 实现是这样的:

I am trying to implement login with Facebook and Twitter. I got it working with Facebook but don't know how to do it with Twitter. Are there any examples? My Facebook implementation is like this:

var auth = new OAuth2Authenticator(
    clientId: "*****************",
    scope: "email",
    authorizeUrl: new System.Uri("https://m.facebook.com/dialog/oauth/"),
    redirectUrl: new System.Uri("http://www.facebook.com/connect/login_success.html"));

StartActivity(auth.GetUI(this));

auth.Completed += (senderFb, eventArgs) =>
{
    if (eventArgs.IsAuthenticated)
    {
        AccountStore.Create(this).Save(eventArgs.Account, "Facebook");

        // Now that we're logged in, make a OAuth2 request to get the user's info.
        var request = new OAuth2Request("GET", new System.Uri("https://graph.facebook.com/me"), null, eventArgs.Account);

        request.GetResponseAsync().ContinueWith(t =>
        {
            if (!t.IsFaulted && !t.IsCanceled)
            {
                var obj = JsonValue.Parse(t.Result.GetResponseText());
                if (obj != null)
                {
                    var user = new UserProfile
                        {
                            FirstName = obj["first_name"],
                            LastName = obj["last_name"],
                            FacebookProfileLink = obj["link"],
                            FacebookToken = eventArgs.Account.Properties["access_token"],
                            Gender = obj["gender"] == "female" ? "Female" : "Male",
                            EmailAddress = obj["email"],
                            DisplayName = obj["name"],
                            Name = obj["name"],
                            LoginName = obj["email"]
                        };
                    SignUpUser(user);
                }
            }
        }, uiScheduler);
    }
};

推荐答案

你可以像这样使用 oauth1.

You can use oauth1 like this.

 this.Authenticator = new OAuth1Authenticator (ConsumerKey, ConsumerSecret, RequestTokenUrl, AuthorizeUrl, AccessTokenUrl, DummyCallBackUrl, (IDictionary<string, string> accountProperties) => {
   string screen_name = "";
   if (accountProperties.TryGetValue("screen_name", out screen_name)) {
      Account a = new Account(screen_name, accountProperties);
      AuthenticatorCompletedEventArgs e = new AuthenticatorCompletedEventArgs(a);
      CompleteAuthentication(e);
   }
   return null;
});

twitter api 不完全支持 OAuth2

twitter api dosen't fully support OAuth2

这篇关于Xamarin.Auth 与 Twitter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆