-
-
Save rossnelson/ca1e9fb0c31031a3c790 to your computer and use it in GitHub Desktop.
Social Media Access
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Getting a JSON Facebook Feed | |
========================================================================== | |
1. Sign in as a developer at https://developers.facebook.com/ | |
2. Click "Create New App" at https://developers.facebook.com/apps | |
3. Under Apps Settings, find the App ID and App Secret | |
*/ | |
$appID = 'XXXX'; | |
$appSecret = 'XXXX'; | |
/* Configuring a JSON Facebook Feed | |
========================================================================== | |
1. Find the desired feed ID at http://findmyfacebookid.com/ | |
2. Set the maximum number of stories to retrieve | |
3. Set the seconds to wait between caching the response | |
*/ | |
$feed = 1215713599; | |
$maximum = 10; | |
$caching = 60; | |
/* Enjoying a JSON Facebook Feed | |
========================================================================== | |
Visit this URL and make sure everything is working | |
Use JSONP by adding ?callback=YOUR_FUNCTION to this URL | |
Tweet love or hate @jon_neal | |
Permission errors? http://stackoverflow.com/questions/4917811/file-put-contents-permission-denied | |
*/ | |
$filename = basename(__FILE__, '.php').'.json'; | |
$filetime = file_exists($filename) ? filemtime($filename) : time() - $caching - 1; | |
if (time() - $caching > $filetime) { | |
$authentication = file_get_contents("https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id={$appID}&client_secret={$appSecret}"); | |
$response = file_get_contents("https://graph.facebook.com/{$feed}/feed?{$authentication}&limit={$maximum}"); | |
file_put_contents($filename, $response); | |
} else { | |
$response = file_get_contents($filename); | |
} | |
header('Content-Type: application/json'); | |
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $filetime).' GMT'); | |
print($_GET['callback'] ? $_GET['callback'].'('.$response.')' : $response); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Getting a JSON Facebook Feed | |
========================================================================== | |
1. Sign in as a developer at https://developers.facebook.com/ | |
2. Click "Create New App" at https://developers.facebook.com/apps | |
3. Under Apps Settings, find the App ID and App Secret | |
*/ | |
$appID = 'XXXX'; | |
$appSecret = 'XXXX'; | |
/* Configuring a JSON Facebook Feed | |
========================================================================== | |
1. Find the desired feed ID at http://findmyfacebookid.com/ | |
2. Set the maximum number of stories to retrieve | |
3. Set the seconds to wait between caching the response | |
*/ | |
$feed = 1215713599; | |
$maximum = 10; | |
$caching = 60; | |
/* Enjoying a JSON Facebook Feed | |
========================================================================== | |
Visit this URL and make sure everything is working | |
Use JSONP by adding ?callback=YOUR_FUNCTION to this URL | |
Tweet love or hate @jon_neal | |
Permission errors? http://stackoverflow.com/questions/4917811/file-put-contents-permission-denied | |
*/ | |
$filename = basename(__FILE__, '.php').'.json'; | |
$filetime = file_exists($filename) ? filemtime($filename) : time() - $caching - 1; | |
if (time() - $caching > $filetime) { | |
$authentication = file_get_contents("https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id={$appID}&client_secret={$appSecret}"); | |
$response = file_get_contents("https://graph.facebook.com/{$feed}/feed?{$authentication}&limit={$maximum}"); | |
file_put_contents($filename, $response); | |
} else { | |
$response = file_get_contents($filename); | |
} | |
header('Content-Type: application/json'); | |
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $filetime).' GMT'); | |
print($_GET['callback'] ? $_GET['callback'].'('.$response.')' : $response); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Getting a JSON Instagram Feed | |
========================================================================== | |
*/ | |
$accessToken = 'XXXX'; | |
/* Configuring a JSON Instagram Feed | |
========================================================================== | |
*/ | |
$userId = '19151466'; | |
/* Enjoying a JSON Twitter Feed | |
========================================================================== | |
*/ | |
$filename = basename(__FILE__, '.php').'.json'; | |
$filetime = file_exists($filename) ? filemtime($filename) : time() - $caching - 1; | |
if (time() - $caching > $filetime) { | |
$url = "https://api.instagram.com/v1/users/{$userId}/media/recent?access_token={$accessToken}"; | |
$curl_request = curl_init(); | |
curl_setopt($curl_request, CURLOPT_CONNECTTIMEOUT, 20); | |
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($curl_request, CURLOPT_URL, $url; | |
$response = curl_exec($curl_request); | |
curl_close($curl_request); | |
file_put_contents($filename, $response); | |
} else { | |
$response = file_get_contents($filename); | |
} | |
header('Content-Type: application/json'); | |
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $filetime).' GMT'); | |
print($_GET['callback'] ? $_GET['callback'].'('.$response.')' : $response); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment