I Use Xamarin.Auth for login with Facebook Account, Facebook'sProfile photo Resolution is not clear in my App.
private void FacebookClicked(object sender)
{
PublicClass.LocalStorage.ClearAllStorage();
Helper.Constants.AuthSignUp = 1;
Helper.Settings.GeneralUserType = "";
DependencyService.Get().facebook();
}
**Dependency Service **
public class FacebookAuth : BaseViewModel, IFacebook
{
public void facebook()
{
var auth = new OAuth2Authenticator(
clientId: "1106049452932664",
scope: "email",
authorizeUrl: new System.Uri("https://m.facebook.com/dialog/oauth"),
redirectUrl: new System.Uri("https://www.facebook.com/connect/login_success.html"));
auth.Completed += Auth_Completed; var ui = auth.GetUI((Activity)Forms.Context); ((Activity)Forms.Context).StartActivity(ui); } private async void Auth_Completed(object sender, AuthenticatorCompletedEventArgs e) { if (e.IsAuthenticated) { UserDialogs.Instance.ShowLoading(); var request = new OAuth2Request( "GET", new System.Uri("https://graph.facebook.com/me?fields=email,name,first_name,last_name,gender,picture"),//https://graph.facebook.com/me?fields=name,picture,cover,birthday //https://graph.facebook.com/me?fields=email,name,first_name,last_name,gender,picture null, e.Account); var fbResponse = await request.GetResponseAsync(); //var fbUserAccessToken = CrossFacebookClient.Current.ActiveToken; var obj = JObject.Parse(fbResponse.GetResponseText()); var email = string.Empty; try { email = obj["email"].ToString().Replace("\"", ""); } catch (Exception ex) { email = "[email protected]"; } var FacebookAccessToken = e.Account.Properties["access_token"]; var json = fbResponse.GetResponseText(); var fbUser = JsonConvert.DeserializeObject<FacebookUserModel>(json); var name = fbUser.name; Helper.Constants.AuthUserEmail = email; Helper.Constants.AuthUserFName = fbUser.name; Helper.Constants.AuthUserLName = fbUser.last_name; Helper.Constants.AuthUserPhone = string.Empty; Helper.Constants.AuthUserProfilePic = fbUser.picture.data.url; Xamarin.Forms.MessagingCenter.Send<string>(Convert.ToString(Helper.Constants.isAuthLogin), "AuthLogin"); } } }
Answers
Try to use fieldname_of_type_ProfilePictureSource instead of picture in get request url , it would return Profile Picture Source.
After i convert the Reponse Data to Json I got that
"picture": {
"data": {
"height": 50,
"is_silhouette": false,
"url": "https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=1805049512960939&height=50&width=50&ext=1587722619&hash=AeQO-1gw",
"width": 50
}
},
I don't know whether it is an existing issue ,as you can see in the sample , the profile pic is low- resolution as well .
Can I ask one more thing.After I login with google ,it remain in the Broswer and can't go back to my app page.Can you help me please?
Do you test on android or iOS ?
it happen in Android,IOS it no problem.
You could start a new activity in OnCreate method , and invoke it via messaging center in Forms project .
Check https://github.com/xamarin/Xamarin.Auth/blob/master/docs/details/issues/open/native-ui-android-customtabs-close.md .