
Untitled
By: a guest on
Jun 14th, 2012 | syntax:
None | size: 1.69 KB | hits: 25 | expires: Never
get page contents and json_decode loading issue
//facebook
$fdata = file_get_contents('http://graph.facebook.com/http://theoatmeal.com/comics/127_hours');
$fdata = json_decode($fdata);
if($fdata->shares) {
$share_count['facebook'] = $fdata->shares;
}
require "facebook.php";
$facebook = new Facebook(array(
'appId' => YOUR_APP_ID,
'secret' => YOUR_APP_SECRET,
));
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
$user = null;
}
}
$result = $facebook->api(...);
<?php if ($user): ?>
<a href="<?php echo $facebook->getLogoutUrl() ?>">Logout of Facebook</a>
<?php else: ?>
<a href="<?php echo $facebook->getLogoutUrl() ?>">Login with Facebook</a>
<?php endif ?>
$fql = 'SELECT total_count FROM link_stat WHERE url="http://google.com"';
$json = file_get_contents('https://api.facebook.com/method/fql.query?format=json&query=' . urlencode($fql));
$data = json_decode($json);
echo $data[0]->total_count;
SELECT url, total_count FROM link_stat WHERE url="..." OR url="..."
$urls = array(
"http://google.com",
"http://twitter.com",
"http://stackoverflow.com",
"http://linkedin.com"
);
function wrap($url) {
return 'url="' . $url . '"';
}
$fql = 'SELECT url, total_count FROM link_stat WHERE ';
$fql .= implode(" OR ", array_map("wrap", $urls));
$json = file_get_contents('https://api.facebook.com/method/fql.query?format=json&query=' . urlencode($fql));
$data = json_decode($json);
array(4) {
[0]=> object(stdClass)#2 (2) {
["url"]=> string(17) "http://google.com"
["total_count"]=> int(1318598)
}
[1] => ...
[2] => ...
[3] => ...
}