Kirti Zare
Kirti Zare

Reputation: 21

Error in getting user profile/detail using Xamarin android and azure facebook authentication

I am using azure mobileservices facebook authentication and xamarin android native app. all configuration i have completed in facebook and azure and also add required permission "public_profile".

Facebook login page is displaying. after adding credential in facebook,I want userprofile from facebook,

But i am getting error "Facebook.FacebookOAuthException: (OAuthException - #1) Bad signature"

My code is

user = await client.LoginAsync(this, MobileServiceAuthenticationProvider.Facebook);

userToken = user.MobileServiceAuthenticationToken;

var fb = new FacebookClient();

fb.AccessToken = userToken;

dynamic me = fb.Get("me?fields=first_name,last_name"); // I am getting error here

string firstname = me.first_name;

Upvotes: 0

Views: 356

Answers (2)

rubStackOverflow
rubStackOverflow

Reputation: 6223

Try this:

var userInfo = await Client.InvokeApiAsync("/.auth/me", 
System.Net.Http.HttpMethod.Get, null);

Upvotes: 0

Adrian Hall
Adrian Hall

Reputation: 8035

You are using the Azure Mobile Auth token to access Facebook. You need to use a Facebook Access token. There are two ways to do this:

1) Use a Facebook Client auth, then submit the facebook token to your azure mobile app to authenticate to the azure mobile app service. This is documented as the "client-managed authentication" in the howto: https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-dotnet-how-to-use-client-library/#authentication

2) DO a GET for https://yoursite.azurewebsites.net/.auth/me while setting the X-ZUMO-AUTH header to the value of userToken - this will return a JSON object that you can parse for the Facebook authentication.

In both cases you will have two access tokens - one for Azure Mobile Apps and one for Facebook. You can then use the facebook token to access the facebook API for additional user information.

Upvotes: 2

Related Questions