I am doing this in Google App Scripts. Seems pretty straightforward, so I first setup Meta Developer info, and created a Instagram Test User and created a valid long-lived token for that account to use.
var userID = "139**********890";
// a fresh Instagram API Long Live Access Token
var accessToken = "IGQVJWRzBzWGp2d1hIUThZ*****************************************************************************************************************cWVFclczbDBmTEx0U1B2RAZDZD";
function insertPost3() {
var formData = {
'image_url': "https://drive.google.com/uc?id=10QubQQV218reR2qSQ-9qA0QmrOoYoCIL&export=download",
'caption': "here is sample text",
'access_token': accessToken
};
var options = {
'method' : 'post',
'payload' : formData,
'muteHttpExceptions' : true
};
const container = 'https://graph.facebook.com/' + userID + '/media';
Logger.log(container);
const response = UrlFetchApp.fetch(container, options);
const creation = response.getContentText();
var data = JSON.parse(creation);
var creationId = data.id
var formDataPublish = {
'creation_id': creationId,
'access_token': accessToken
};
var optionsPublish = {
'method' : 'post',
'payload' : formDataPublish
};
const sendinstagram = 'https://graph.facebook.com/' + userID + '/media_publish';
UrlFetchApp.fetch(sendinstagram, optionsPublish);
}
And just getting a generic error back, even with muteHttpExceptions. Not sure how to proceed.
Exception: Request failed for https://graph.facebook.com returned code 400. Truncated server response: {"error":{"message":"Invalid OAuth access token.","type":"OAuthException","code":190,"fbtrace_id":"AhuSzful3sLsd7qKziJH6Oi"}} (use muteHttpExceptions option to examine full response)
Any ideas, sample code, or resources to read would be great.
This is one of the guides I've been using to do this: https://developers.facebook.com/docs/instagram-api/guides/content-publishing/
Thanks for any help!!
phi