Search code examples
c#wpffacebook-graph-apiinstagram-api

Retrieve photos from Facebook/Instagram


I am looking to retrieve photos from Facebook and Instagram for viewing in a WPF application. The idea behind is to show user existing photos and allow them to upload more using C#. A bonus would be to let the user delete photos and set their profile picture, but is not a must.

I cannot find any APIs for either Facebook or Instagram for use in a WPF application, and the ones I did find were all for web (ASP.NET/PHP).

Is there such an API and how might I go about doing this?


Solution

  • Facebook Graph .NET API.

    Using the Facebook .NET SDK

    Here is an example I whipped up, haven't tested. Should work though. It retrieves the profile picture of a user. Though if you read through the APIs you can adapt it for whatever you need.

    var client = new FacebookClient("accessToken");
    
    object taskResult = await client.GetTaskAsync("/me");
    var result = (IDictionary<string, object>)taskResult;
    var userId = taskResult.Where(s=>s.Key == "id").First().Value
    
    var profilePicUrl = string.Format("https://graph.facebook.com/{0}/picture", userId);
    

    Facebook SDK