Skip to content

Instantly share code, notes, and snippets.

@jxxe
Created May 30, 2020 16:56
Show Gist options
  • Save jxxe/890ed1493e1de3eedf452f17b4bc916c to your computer and use it in GitHub Desktop.
Save jxxe/890ed1493e1de3eedf452f17b4bc916c to your computer and use it in GitHub Desktop.
MemeCitations Instagram Fix
<?php
header('Content-Type: application/json');
if(!empty($_POST)) {
$post = $_POST;
$post = json_decode($post, true);
$data = file_get_contents('https://api.instagram.com/oembed/?url=' . $post['url']);
$data = json_decode($data, true);
$dom = new DomDocument();
@$dom->loadHTML($data['html']);
$dates = $dom->getElementsByTagName('time');
foreach($dates as $date) {
$date = $date->getAttribute('datetime');
break;
}
$date = date('j M Y', strtotime($date));
$citation = 'MLA Citation:
@' . $data['author_name'] . ' "' . substr($data['title'], 0, 10) . '..." Instagram, ' . $date . ', ' . $post['url'] . ' #MemeCitations';
$response = [
'success' => true,
'citation' => $citation
];
$response = json_encode($response);
print_r($response);
} else {
echo '{"error":{"type":"miss"}}';
}
@jxxe
Copy link
Author

jxxe commented May 30, 2020

I'm not sure what you've built the /api/create part of your site with. Wappalyzer says that it's PHP, so that's what I'm going to go with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment