Xamarin.Auth与Twitter(Xamarin.Auth with Twitter)

2019-08-31 23:03发布

我试图实现登录与Facebook和Twitter。 我得到了它与Facebook工作,但不知道如何与Twitter的做到这一点。 是否有任何的例子吗? 我的Facebook的实现是这样的:

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);
    }
};

Answer 1:

您可以使用您好!OAuth1这样。

 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



文章来源: Xamarin.Auth with Twitter