Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,206 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am trying to authenticate and get user details from linkedin using xamarin forms. I am using Xamarin. Auth and Xamarin. Auth.XamarinForms.
private void OnLinkedInClicked()
{
try
{
var authenticator = new OAuth2Authenticator(
clientId: "***",
clientSecret: "****",
scope: "r_liteprofile",
authorizeUrl: new Uri("https://www.linkedin.com/uas/oauth2/authorization"),
redirectUrl: new Uri("***"),
accessTokenUrl: new Uri("https://www.linkedin.com/uas/oauth2/accessToken"),
null,
false);
var page = new AuthenticatorPage(authenticator);
authenticator.Completed += OnLinkedInAuthenticationComplete;
Application.Current.MainPage.Navigation.PushModalAsync(page);
}
catch (Exception ex)
{
}
}
private async void OnLinkedInAuthenticationComplete(object sender, AuthenticatorCompletedEventArgs e)
{
if (!e.IsAuthenticated)
{
//Show error message to the user
return;
}
try
{
// request user data from LinkedIn
var request = new OAuth2Request(
"GET",
new Uri("https://api.linkedin.com/v2/me?"
+ "format=json"
+ "&oauth2_access_token="
+ e.Account.Properties["access_token"]),
null,
e.Account);
request.AccessTokenParameterName = "oauth2_access_token";
var linkedInResponse = await request.GetResponseAsync();
var json = linkedInResponse.GetResponseText();
var user = GetUserFromLinkedInJson(json);
if (user == null) return;
ContinueToNextPage(user);
}
catch (Exception ex)
{
}
}
Though I am getting the access_ token But while requesting user data, linkedInResponse i.e request.GetResponseAsync();, is throwing this exception
{ "serviceErrorCode": 65601, "message": "The token used in the request has been revoked by the user", "status": 401 }
Any soultion plz....