Home > database >  How to get Public Instagram User Posts with React?
How to get Public Instagram User Posts with React?

Time:12-08

I have a REACT application, it is a portfolio site for a children's fashion store, I want to link the instagram posts on the site. The store's Instagram is a public instagram. In the old days I could easily get everything related to a particular instagram profile using the URL https://www.instagram.com/nameOfPublicUser/?a__=1 Today I get a Cross-Origin Read Blocking (CORB) error where the API call is not allowed. Reading the developers.facebook.com documentation, they tell me to use the GraphAPI.

Reading the GRAPHAPI documentation, it informs us that it is necessary to get access tokens to be able to use the GraphAPI.

Reading the ACCESS TOKEN documentation, in order to perform queries to the graphAPI we must have the permission of the user that is accessing our application, i.e., my brochure site. From the moment he logs in we need to get his authorization, and we do this through Facebook Login.

Reading the FACEBOOK LOGIN documentation, we must "register" our app at developers.facebook.com and implement the Facebook SDK for Javascript.

Anyway, so much work to just pull PUBLIC data from a PUBLIC profile to display on my site. Is there an easy call API to bring up the POSTS from a public instagram profile?

CodePudding user response:

It is not currently possible to use React to get public Instagram user posts, as the Instagram API does not provide access to this information. The Instagram API is intended for use by authorized applications that have been approved by Instagram and given access to specific endpoints. Access to public user posts is not available through the Instagram API.

If you want to access public Instagram user posts in a React project, you will need to use a different method, such as scraping the user's public profile page to extract the information you need. However, be aware that this is against Instagram's terms of service and may not be allowed. It is always best to check the terms of service of any platform before attempting to access its data in this way.

Using Selenium:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# Set up the webdriver
driver = webdriver.Chrome()

# Navigate to the user's profile page
driver.get('https://www.instagram.com/<username>')

# Wait for the page to load
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'div.v1Nh3')))

# Get all the posts on the page
posts = driver.find_elements_by_css_selector('div.v1Nh3')

# Print the number of posts
print(f'Found {len(posts)} posts')

# Loop through the posts and print their captions
for post in posts:
  caption = post.find_element_by_css_selector('div.C4VMK span').text
  print(caption)

# Close the webdriver
driver.close()

CodePudding user response:

Take a look on the API Basic Display for Instagram: https://developers.facebook.com/docs/instagram-basic-display-api/overview

  • Related