Search code examples
google-apps-scriptinstagramgoogle-appsinstagram-api

Getting Instagram API with Google Apps Scripting


I have a list of 500 Instagram usernames in a spreadsheet. I want to extract the bio of all 500 accounts and put those in a spreadsheet. I am using Google Apps Scripting. I don't know how to get access to instagram's api where I can access the bio. I've look at other websites where I can pull up the Instagram accounts bio (like http://www.pikore.com/humordailyy) but those still don't have API. Is there a way I can get API? If not, is there a way I can crawl through the HTML or something to get the bio? Thank you.


Solution

  • As discussed in documentation, Instagram API requires authentication - specifically requests made on behalf of a user. Authenticated requests require an access_token which you could receive by doing the following:

    1. Direct the user to our authorization url.

      • If the user is not logged in, they will be asked to log in.
      • The user will be asked if they would like to grant your application access to her Instagram data.
    2. The server will redirect the user in one of two ways that you choose:

      • Server-side flow
      • Implicit flow: This method is less secure, but allows applications without any server component to receive an access_token.

    For Implicit Authentication Flow which is for applications without any server component, simply follow these steps:

    Step One: Direct your user to our authorization URL

    https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token
    

    At this point, Instagram present the user with a login screen and then a confirmation screen where they grant your app’s access to their Instagram data. Please note that you may provide an optional scope parameter to request additional permissions outside of the “basic” permissions scope.

    Step Two: Receive the access_token via the URL fragment

    Once the user has authenticated and then authorized your application, Instagram redirects them to your redirect_uri with the access_token in the url fragment. It will look like this:

    http://your-redirect-uri#access_token=ACCESS-TOKEN
    

    Simply grab the access_token off the URL fragment and you’re good to go. If the user chooses not to authorize your application, you’ll receive the same error response as in the explicit flow.

    • error: access_denied

    • error_reason: user_denied

    • error_description: The user denied your request