Reputation: 826
I am working on a web app in which some content is generated in the form of text (and will soon include images as well). I want to add a share button which will allow the user to add this content to their Instagram story.
So the flow of this is going to be:
- User does something on the website
- The website generates some content based on user input
- User clicks on "Share on Instagram" and posts it on his/her story
Is there a way to do this using Javascript or an API call like the Twitter share option directly from the HTML ?
I am using Python on the backend (Flask) and JS on the frontend
Upvotes: 15
Views: 39006
Reputation: 1
function InstagramShare($url = null){
// Redirect User to Instagram for Authentication
if (!isset($_GET['code'])) {
$authUrl = $this->getInstagramAuthUrl();
return $this->redirect($authUrl);
}
// Handle the Redirect and Exchange Code for Access Token
$code = $_GET['code'];
$accessTokenData = $this->getAccessToken($code);
if (isset($accessTokenData['access_token'])) {
$shortLivedToken = $accessTokenData['access_token'];
$longLivedTokenData = $this->getLongLivedToken($shortLivedToken);
if (isset($longLivedTokenData['access_token'])) {
$longLivedToken = $longLivedTokenData['access_token'];
$this->shareStory($longLivedToken, $url);
} else {
throw new \Exception('Failed to exchange short-lived token for long-lived token.');
}
}
else {
throw new \Exception('Failed to retrieve access token.');
}
}
Upvotes: -1
Reputation: 403
Instagram recently released a new feature enabling this functionality on mobile. Please check out this post for details.
Quick summary, you can use the navigator.share
API to share images straight from web to Instagram, directly opening a Post, Story, or Message in Instagram with the image included.
Upvotes: 0
Reputation: 425
OK, lets make this simple.
The direct answer as found on the official Facebook developers page is no. You can't trigger an API to create an instagram story, as for now only the "read-mode" is supported through API.
But as most things in life you can hack your way around.
You can create a button that says, "share on your instagram stories" and here's what it is gonna do:
UPDATE
- Trigger the open story camera in Instagram app with this link: instagram://story-camera. (the last content they have will be the content u sent and will be the first thing they see for posting a story)
There is a better solution for the third point:
It goes without saying that this will work when the website is opened in a phone and not in a desktop browser as in desktop you can't post stories.
Upvotes: 18
Reputation: 21
The New York Times has done this.
In iOS, it generates an Instagram Story, with the headline and lede of the respective news article.
To do this, you'll have press the "share" button on an iPhone and then "Instagram Stories."
Auto generated Instagram Story, via The New York Times iOS app
Twitter has also done this for quite a while.
Upvotes: 2