Skip to content

IG User Media

Justin Stolpe edited this page May 21, 2022 · 18 revisions

Get and create media posts for a user.

Getting a Users Media

Get the users media.

use Instagram\User\Media;

$config = array( // instantiation config params
    'user_id' => $userId,
    'access_token' => $accessToken,
);

// instantiate user media
$media = new Media( $config );

// initial user media response
$userMedia = $media->getSelf();

Creating an Image IG Container

Create an image IG Container for use in the post publishing process.

use Instagram\User\Media;

$config = array( // instantiation config params
    'user_id' => '<USER_ID>',
    'access_token' => '<ACCESS_TOKEN>',
);

// instantiate user media
$media = new Media( $config );

$imageContainerParams = array( // container parameters for the image post
    'caption' => '<CAPTION>', // caption for the post
    'image_url' => '<IMAGE_URL>', // url to the image must be on a public server
    'is_carousel_item' => <BOOLEAN>, // is this in a carousel
    'location_id' => '<LOCATION_ID>', // can be left blank otherwise the id of the facebook page associated with the location you want tagged
    'user_tags' => array( // array of users to tag in the image
        array( // key values for the tagged user
             'username' => '<USERNAME>', // user being tagged
             'x' => '<COORD_X>', // range 0.0 - 1.0 of where in the image the user gets tagged
             'y' => '<COORD_Y>' // range 0.0 - 1.0 of where in the image the user gets tagged
        )
    )
);

// create image container
$imageContainer = $media->create( $imageContainerParams );

// get id of the image container
$imageContainerId = $imageContainer['id'];

Creating a Video IG Container

Create an video IG Container for use in the post publishing process.

use Instagram\User\Media;

$config = array( // instantiation config params
    'user_id' => '<USER_ID>',
    'access_token' => '<ACCESS_TOKEN>',
);

// instantiate user media
$media = new Media( $config );

$videoContainerParams = array( // container parameters for the video post
    'caption' => '<CAPTION>', // caption for the post
    'video_url' => '<VIDEO_URL>', // url to the video must be on a public server
    'media_type' => '<MEDIA_TYPE>', // specifying this should be set to VIDEO
    'is_carousel_item' => <BOOLEAN>, // is this in a carousel
    'location_id' => '<LOCATION_ID>', // can be left blank otherwise the id of the facebook page associated with the location you want tagged
    'thumb_offset' => <THUMB_OFFSET> // number of milliseconds in the video to grab the thumbnail
);

// create video container
$videoContainer = $media->create( $videoContainerParams );

// get id of the video container
$videoContainerId = $videoContainer['id'];

Creating a Carousel IG Container

Create an carousel IG Container for use in the post publishing process.

use Instagram\User\Media;

$config = array( // instantiation config params
    'user_id' => '<USER_ID>',
    'access_token' => '<ACCESS_TOKEN>',
);

// instantiate user media
$media = new Media( $config );

$carouselContainerParams = array( // container parameters for the carousel post
    'caption' => '<CAPTION>', // caption for the post
    'children' => array( // array of container ids for the carousel up to 10 max
        '<CONATAINER_ID'>,
        '<CONATAINER_ID'>
    ),
    'location_id' => '<LOCATION_ID>', // can be left blank otherwise the id of the facebook page associated with the location you want tagged
    'user_tags' => array( // array of users to tag in the image
        array( // key values for the tagged user
             'username' => '<USERNAME>', // user being tagged
             'x' => '<COORD_X>', // range 0.0 - 1.0 of where in the image the user gets tagged
             'y' => '<COORD_Y>' // range 0.0 - 1.0 of where in the image the user gets tagged
        )
    )
);

// create carousel container
$carouselContainer = $media->create( $carouselContainerParams );

// get id of the image container
$carouselContainerId = $carouselContainer['id'];
Clone this wiki locally