Skip to content

Instantly share code, notes, and snippets.

@l0c0luke
Last active January 14, 2019 23:56
Show Gist options
  • Save l0c0luke/878ff677f90b3de382416a69bcaf18a5 to your computer and use it in GitHub Desktop.
Save l0c0luke/878ff677f90b3de382416a69bcaf18a5 to your computer and use it in GitHub Desktop.
Crowd Tangle API snippet
// Crowdtangle API to check for 3rd_party posts on facebook.
$today = new \DateTime();
if ($fullCrowdTangle) {
$startDate = '';
} else {
$startDate = '&startDate='.$today->sub(new \DateInterval('P28D'))->format('Y-m-d');
}
$ctUrl = 'https://api.crowdtangle.com/links?link='.$fullUrl.$startDate;
$ctUrl .= '&platforms=facebook&token=SUPERCOOLTOKEN';
try {
// Create the guzzle request dynamically based on the parameters we have set
$client = new Client();
$request = $client->get($ctUrl);
$response = $request->send();
$ctResponse = json_decode($response->getBody(), true);
if ($ctResponse['status'] == 200) {
foreach ($ctResponse['result']['posts'] as $ctPost) {
// we dont care about our own links, we do a pretty good job of that already
if ($ctPost['account']['handle'] !== 'someecards') {
print_r($ctPost);
}
}
} else {
$app->log(
sprintf('Error getting crowd tangle info for %s', $ctUrl),
array(),
Logger::ERROR
);
}
} catch (\Exception $e) {
$app->log(
sprintf('Error getting crowd tangle info for %s', $ctUrl),
array('Exception' => $e),
Logger::ERROR
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment