Ricardo-FM / cest.github.io

0 stars 1 forks source link

Instagram Basic API Display #14

Open JadeP27 opened 3 years ago

JadeP27 commented 3 years ago

AS AN user I WANT to view photos SO THAT I can understand what the business provides

Make calls to Instagram and return image URL Filter by tags and usernames

Dev Resource: https://stackoverflow.com/questions/14105551/filter-instagram-api-results-by-tag-and-username

JadeP27 commented 3 years ago

Instagram Basic API Display is subject to Graph api Limits - Calls within one hour = 200 * Number of Users

api.instagram.com — for getting Instagram User Access Tokens graph.instagram.com — for getting Instagram user profiles and media

The Authorization Window allows your app to get Authorization Codes and permissions from app users. Authorization Codes can be exchanged for Instagram User Access Tokens, which must be included when querying an app user's profile or their media.

Short-lived tokens that have not expired can be exchanged for long-lived access tokens which are valid for 60 days. Long-lived tokens for public Instagram accounts can be refreshed before they expire by querying the GET /refresh_access_token endpoint. Tokens for private accounts, however, cannot be refreshed.

In order to test your app with an Instagram User, you must first send an invitation to the Instagram User's account and accept the invitation. Invitations can be sent from the Instagram Testers section in the App Dashboard > Roles > Roles tab. Invitations can be accepted by the Instagram User in the (Profile Icon) > Edit Profile > Apps and Websites > Tester Invites section of the Instagram website or mobile app after signing into their account.

Apps designated as Business apps are not supported. If your app is a Business app use the Instagram Graph API instead, or create a new, non-Business app.

GET AUTHORIZATION: https://api.instagram.com/oauth/authorize ?client_id={instagram-app-id} &redirect_uri={redirect-uri} &scope={scope} &response_type=code &state={state} (this is the only optional field)

example https://api.instagram.com/oauth/authorize ?client_id=990602627938098 &redirect_uri=https://socialsizzle.herokuapp.com/auth/ &scope=user_profile,user_media &response_type=code

will return Auth Code through the code query parameter (capture it) this is your Access Token Exchange this for the short lived IG user token valid for 1 or 2 hours by using the following post request end point & parameters ----->

POST https://api.instagram.com/oauth/access_token client_id={'numeric string'} client_secret={'string'} code={'string'} grant_type={'string'} redirect_uri={'string'}

Then send Get request to the following endpoint replacing {fields} with a comma-separated list of User fields you want returned----->

GET /me?fields={fields}&access_token={access-token}

Exchange for Long-Lived IG token (60 days) - request are made via server-side. Which requires a valid (unexpired) short-lived Instagram User Access Token and Your Instagram App Secret (App Dashboard > Products > Instagram > Basic Display > Instagram App Secret) ----->

Example Request curl -i -X GET "https://graph.instagram.com/access_token ?grant_type=ig_exchange_token &client_secret={instagram-app-secret} &access_token={short-lived-access-token}

To Refresh (must be unexpired) curl -i -X GET "https://graph.instagram.com/refresh_access_token ?grant_type=ig_refresh_token &access_token={long-lived-access-token}"