How to Get Instagram Stories Using PHP
Are you an online store that dived into social media marketing? If yes, and if Instagram is your forte, this post is for you.
With social media platforms getting popular each day, businesses have started preferring social media marketing over traditional marketing techniques.
Moreover, Instagram is one of the top social media platforms for businesses to make the most out of it. Majority of the businesses have started selling on Instagram and harnessing its benefits.
The below numbers says it all:
- More than 25 million businesses are using Instagram for online business – Hootsuite
- One-third of the most viewed stories are from brands and that 60 percent of total users discover new brands or products on the platform – Instagram
- In late 2019, Instagram Stories had 500 million monthly active users. – Statista
Leverage Instagram for your E-commerce business because the numbers won’t lie! Reach your intended audience using Instagram.
Unlike posts on Instagram, stories have a more interactive element that online stores can use creatively by mixing in things like videos, swiping, and polls.
Instagram story is the feature of the app allowing users to post photo and video sequences that disappear after 24 hours of being posted.
Now, if you want to go one step ahead and fetch Instagram stories using Php in your online store, you can do so using the method given in this post.
Display the Instagram stories to your store visitors and encourage them to make the purchase in your store.
Steps to Get Instagram Stories Using PHP
In order to get the story, you first need to get the access token and page ID.
Steps to get access token:
- Create Facebook app (https://developers.facebook.com/docs/development#register)
- Go to Add a New App ( https://developers.facebook.com/apps/)
- On click of “Add a New App”, it will open a popup to create an App ID. Select the option “For Everything Else”.
- Enter App Display Name and click Create App ID button.
- Complete security check and click Submit button and it will redirect you to the Manager app dashboard page.
- In Manager app dashboard, go to Setting > Advanced
- Under the section ‘Business Manager’, select a Business Manager or create a Business Manager then save this setting.
- After ‘Save Changes’, click the ‘Configure in Business Manager’ button under the “Business Manager” section. It will redirect to the Business setting dashboard.
- Setting Business Account:
- Create a system user (or reuse an existing one) for this business in Business Settings under Users > System Users tab
- Add the system used above as someone who acts as an admin for a Page you’re about to generate an access token for. (Add the system user to a selected Page by clicking Add People button under the Accounts > Pages tab.)
- Add the Assets by clicking the Add Assets tab
- Select Assets type(Pages and Apps), Assets, and Set Permissions for generating a new token. (here admin has all Permissions)
- After adding the assets and people, click “Generate New Token”. Select an app for which you want to generate the token.
- Select all the required permission and click “Generate Token”.
- After clicking ‘Generate Token’, you will receive a token, copy it.
- After receiving the token, go to Facebook for Developers and click Tools > Access Token Debugger.
- Paste the Token here and Debug it.
- You can see Token Information like expiry date, validity, origin, scopes, etc.
- Enter your Facebook page ID. Follow the steps below to find your Facebook page ID.
Steps to get Facebook Page ID:
- When you create a new Facebook page, the page ID is given. If you want to find the page ID of an already existing page, visit the page and check the URL. The characters in the URL after the page name is your page ID. For example, the URL is https://www.facebook.com/Test-Business-2387482487989307
- Here the name of the page is “Test Business” and the digits 2387482487989307 is the page ID.
- Or, you can get the Page ID from the Page “About” section (only when Logged in to your Facebook) under “More Info”.
We get the token and Facebook page ID. Now we use both to get instagram_business_account_id.
Steps to get instagram_business_account_id:
In order to get the business_account_id, we need to pass the below URL:
1 |
https://graph.facebook.com/v5.0/{fb_page_id}?fields=instagram_business_account&access_token={access_token} |
Pass your facebook_page_id and access_token that we’ve got from above steps.
Here we go, it returns “instagram_business_account_id” as shown in the below image.
Next, we need to get the media id (story id) using business_account_id and access_token.
1 |
https://graph.facebook.com/v10.0/{bussiness_account_id}/stories/?access_token={access_token} |
It returns the story_id, as shown below:
We have all the required ids to get Instagram stories using PHP. Now get the Instagram Story.
Steps to get the Instagram Story:
Pass the below URL:
1 |
https://graph.facebook.com/v5.0/{story_id}/?access_token={access_token}&fields=id,media_type,media_url,owner,timestamp,username,thumbnail_url,shortcode,like_count,comments_count,caption |
The Instagram story data that has been get will look like below:
Now use this story data wherever you want to display the Instagram stories.
It will display up to 24 hours as the lifespan of Instagram stories is 24 hours.
That’s all!
If you don’t want to limit till Instagram stories, but also want to fetch Instagram posts to your Magento 2 store, Meetanshi offers Magento 2 Instagram extension that integrates Magento 2 with Instagram to fetch Instagram images, edit and show them in the front-end to give a look and feel of an amazing Instagram shop in Magento 2 stores.
If you want the same solution for Magento 1, check the Magento Instagram extension.
Use this method and leverage the benefit of marketing through Instagram stories.
If you have any doubts regarding this post, just mention them in the Comments section below, and do not forget to share how this post helped you to increase sales!
I would be glad to help.
Feel free to share the solution with Magento Community via social media.
Thank You.
Fetch Instagram images, edit & show them in the front-end to give a look & feel of an Instagram shop in Magento 2 stores.
Jignesh Parmar
An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.
Prev
How to Get Magento 2 Collection Count
How to Get Customer by Email in Magento 2
Next