Question about the id on media items. The ids are in this form:
198319604945554515_31149514
What is the number after the _
? And can I assume that the part before the _
is unique?
Apparently using just the first part in GetMedia queries works.
First you ask:
What is the number after the
_
?
That is the user ID for the media ID in question.
And can I assume that the part before the
_
is unique?
Yes and no.
I’ve been experimenting with the Instagram API myself and have been curious about the media ID format, so tripped across this question and am posting an answer to expand on the comments already made.
Basically, the part before the _
is based on the timestamp connected with the media item itself; uploaded or creation I assume. This is based on johnnyg17
’s comment—which is a correct assessment of the string format—and can be converted to Unix date format quite easily.
That said, the only true “uniqueness” of the ID comes from the combination of the part before the _
as well as the user ID after that.
Since the first part is clearly derived from a timestamp, and millions of users use Instagram all the time, the chances of multiple users uploading images with the same timestamp is quite high. It cannot be considered “unique” on its own since using just that number for ID purposes potentially runs into ID collisions which is definitely a scaling issue.
So the Instagram media ID gets around this issue by combining the timestamp-based item before the _
with the unique user ID that follows it. That combo is what makes the media ID unique.
And to prove that the first part of the ID is indeed based on a Unix timestamp — as johnnyg17
’s comment explains — I whipped this up in PHP using some media IDs I have access to; the “user id” is of course changed to 123456789
to preserve privacy.
$test_array = array();
$test_array[] = "1388611234533808001_123456789";
$test_array[] = "1389294690389553994_123456789";
$test_array[] = "1390349053757443491_123456789";
$test_array[] = "1391541737234771515_123456789";
$test_array[] = "1392560455737690245_123456789";
$test_array[] = "1392592260868093320_123456789";
foreach ($test_array as $test_value) {
$split_string = mb_split('_', $test_value);
$unix_time = round(($split_string[0]/1000000000000 + 11024476.583915909500)/0.008388608000);
echo date("F j, Y, h:i:s a", $unix_time);
echo ' | ';
echo '<b>Instagram ID String</b>: ' . $split_string[0] . ' | <b>User ID</b>: ' . $split_string[1] . '<br />';
}
Running that produces the following output:
November 21, 2016, 02:09:40 pm | Instagram ID String: 1388611234533808001 | User ID: 123456789
November 22, 2016, 12:47:34 pm | Instagram ID String: 1389294690389553994 | User ID: 123456789
November 23, 2016, 11:42:24 pm | Instagram ID String: 1390349053757443491 | User ID: 123456789
November 25, 2016, 03:12:03 pm | Instagram ID String: 1391541737234771515 | User ID: 123456789
November 27, 2016, 12:56:04 am | Instagram ID String: 1392560455737690245 | User ID: 123456789
November 27, 2016, 01:59:15 am | Instagram ID String: 1392592260868093320 | User ID: 123456789