skip to Main Content

We have an Web API (ASP.net & C#) project that collects recent posts (by our organisation) from all four different social networking sites (facebook, twitter, youtube and instagram) and pass them on as json feed to websites and mobile apps.

Luckily, both Facebook and Twitter provides Oauth “client_credentials” flows which allows me to get token when I make a POST request to “token endpoint” with client id, client secret and grant type as “client_credential” as shown below:

https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&grant_type=client_credentials

But I am not sure how to tackle Instagram API because it doesn’t give a “client_credentials” flow. Since the token retrieval needs to happen at the backend within a function without an explicit authentication in a web browser.

Has anyone solved this problem?

2

Answers


  1. My way in my old projects. I’m just checking access token still usable. If not open an iframe or popup for get new one. So your mainframe not need to refresh.

    retrieving Instagram access_token via api in c# a

    You’re going to need to have this available publicly all the time for
    anyone who authenticates. If the token expires, you need to pop up the
    login auth view again. It’s an awful method of authentication, and I
    truly wish they offered a full OAuth2 authentication handshake that
    could be done just with GET. But they don’t, which is why all the 3rd
    party apps you see out there have the Authorize page appear after you
    log in. – brandonscrip

    Login or Signup to reply.
  2. If you just want to read Instagram posts.

    I know this is a bit late, but i am working on a similar application and i read a post here (stackoverflow) on how to get the Instagram posts. I couldn’t note down the link to the original post, so i am just rewriting the post here. If i find the original post i will add the link here. If anyone finds it, please add it in comments.

    Instagram posts can be obtained with the help of your username and with this url:
    https://www.instagram.com/YOUR_USER_NAME/media
    ex: https://www.instagram.com/NBA/media.

    This returns a list of posts, not sure how long. But it returned 20 posts of mine. It also has ‘”more_available”: true,’ so it should be possible to get more.

    C# code to get this:

    string username = "<YOUR_USER_NAME>";
    string url = "https://www.instagram.com/"+ username + "/media/";
    
    HttpWebRequest instaRequest = WebRequest.Create(url) as HttpWebRequest;
    //optional
    HttpWebResponse instaResponse = instaRequest.GetResponse() as HttpWebResponse;
    string rawJson = new StreamReader(instaResponse.GetResponseStream()).ReadToEnd();
    
    JObject InstagramJsonFeeds = JObject.Parse(rawJson);
    // Loop through JObject and get the details
    foreach (var Property in InstagramJsonFeeds["items"])
    {
        var ImageUrl = Property["images"]["standard_resolution"]["url"].ToString();
        DateTime DTime = new DateTime(1970, 1, 1).AddSeconds(double.Parse(Property["created_time"].ToString()));
    
        // Etc Etc ......
    }
    

    Let me know if this helps.

    How to do it with CURL:
    http://blog.eezgu.com/2017/03/how-to-get-latest-images-from-instagram.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search