How to retrieve facebook profile picture from logged in user with asp net core I

Introduction

ASP.NET is a popular programming language used for web . In this article, we will discuss how to retrieve a picture from a logged-in user using ASP.NET Core.

Step 1: Set up Facebook Login

The first step is to set up Facebook Login in your ASP.NET Core application. This involves creating a Facebook app and the necessary settings.


// Facebook Login 
services.()
    .AddFacebook(options =>
    {
        options.AppId = "YOUR_APP_ID";
        options.AppSecret = "YOUR_APP_SECRET";
    });

Step 2: Retrieve the Profile Picture

Once the Facebook Login is set up, you can retrieve the profile picture of the logged-in user. This can be done by making a request to the Facebook API.


// Retrieve the profile picture
var httpClient = new HttpClient();
var accessToken = await HttpContext.GetTokenAsync("access_token");

httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

var response = await httpClient.GetAsync("https://graph.facebook.com/me/picture?type=large&redirect=false");
var content = await response.Content.ReadAsStringAsync();

var pictureUrl = JObject.Parse(content)["data"]["url"].ToString();

Step 3: Display the Profile Picture

Finally, you can display the retrieved profile picture on your ASP.NET Core application. This can be done by using the obtained picture URL in an HTML tag.


// Display the profile picture
Profile Picture

Conclusion

In this article, we have discussed how to retrieve a Facebook profile picture from a logged-in user using ASP.NET Core. By following the outlined above, you can easily Facebook Login into your ASP.NET Core application and display the profile picture of the logged-in user.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents