2
Xamarinフォームを使用して1つのクロスプラットフォームアプリを開発しました。私は1つのFacebookの問題に立ち往生しています。だから私の質問は、Facebookのユーザーのプロフィール情報を取得する方法です。私はちょうどユーザーの "ID"と "名前"を取得することができます。xamarin.authを使用してfacebookにログインしてユーザーのプロフィール情報を取得する方法
protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
{
base.OnElementChanged(e);
// this is a ViewGroup - so should be able to load an AXML file and FindView<>
var activity = this.Context as Activity;
var auth = new OAuth2Authenticator (
clientId: App.Instance.OAuthSettings.ClientId, // your OAuth2 client id
scope: App.Instance.OAuthSettings.Scope, // The scopes for the particular API you're accessing. The format for this will vary by API.
authorizeUrl: new Uri (App.Instance.OAuthSettings.AuthorizeUrl), // the auth URL for the service
redirectUrl: new Uri (App.Instance.OAuthSettings.RedirectUrl)); // the redirect URL for the service
auth.AllowCancel = true;
auth.Completed += LoginComplete;
activity.StartActivity (auth.GetUI(activity));
}
public async void LoginComplete(object sender, AuthenticatorCompletedEventArgs e)
{
// We presented the UI, so it's up to us to dismiss it.
// DismissViewController(true, null);
if (!e.IsAuthenticated)
{
Console.WriteLine("Not Authorised");
return;
}
var accessToken = e.Account.Properties["access_token"].ToString();
var expiresIn = Convert.ToDouble(e.Account.Properties["expires_in"]);
var expiryDate = DateTime.Now + TimeSpan.FromSeconds(expiresIn);
// Now that we're logged in, make a OAuth2 request to get the user's id.
var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me"), null, e.Account);
var response = await request.GetResponseAsync();
var obj = JObject.Parse(response.GetResponseText());
var id = obj["id"].ToString().Replace("\"", ""); // Id has extraneous quotation marks
// var user = await ParseFacebookUtils.LogInAsync(id, accessToken, expiryDate);
}
おそらくこれが役立ちます:http://stackoverflow.com/questions/24105390/how-to-login-to-facebook-in-xamarin-forms –