Skip to content

Instantly share code, notes, and snippets.

@jasoniangreen
Last active May 7, 2019 10:21
Show Gist options
  • Save jasoniangreen/8763927358c603302dd4cfda6912529e to your computer and use it in GitHub Desktop.
Save jasoniangreen/8763927358c603302dd4cfda6912529e to your computer and use it in GitHub Desktop.
Upload Photo with emoji in hashtag
<?php
set_time_limit(0);
date_default_timezone_set('UTC');
require __DIR__.'/../vendor/autoload.php';
/////// CONFIG ///////
$username = '';
$password = '';
$debug = true;
$truncatedDebug = false;
//////////////////////
/////// MEDIA ////////
$photoFilename = '';
//////////////////////
$ig = new \InstagramAPI\Instagram($debug, $truncatedDebug);
try {
$ig->login($username, $password);
} catch (\Exception $e) {
echo 'Something went wrong: '.$e->getMessage()."\n";
exit(0);
}
// Now create the metadata array:
$metadata = [
// (optional) Captions can always be used, like this:
'caption' => '#love😍 This is a great API!',
// (optional) To add a hashtag, do this:
'hashtags' => [
// Note that you can add more than one hashtag in this array.
[
'tag_name' => 'love😍', // Hashtag WITHOUT the '#'! NOTE: This hashtag MUST appear in the caption.
'x' => 0.5, // Range: 0.0 - 1.0. Note that x = 0.5 and y = 0.5 is center of screen.
'y' => 0.5, // Also note that X/Y is setting the position of the CENTER of the clickable area.
'width' => 0.24305555, // Clickable area size, as percentage of image size: 0.0 - 1.0
'height' => 0.07347973, // ...
'rotation' => 0.0,
'is_sticker' => false, // Don't change this value.
'use_custom_title' => false, // Don't change this value.
],
],
];
try {
$photo = new \InstagramAPI\Media\Photo\InstagramPhoto($photoFilename, ['targetFeed' => \InstagramAPI\Constants::FEED_STORY]);
$ig->story->uploadPhoto($photo->getFile(), $metadata);
} catch (\Exception $e) {
echo 'Something went wrong: '.$e->getMessage()."\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment