Stworzyłem prosty widget do wyświetlania jednego postu ze strony na Facebooku. Oto kod:Facebook Graph Api uzyskać obraz połączonych postów
//VARS
$title = $instance['title'];
$app_id = $instance['add_id'];
$app_secret = $instance['app_secret'];
$page_id = $instance['pade_id'];
$my_url = $instance['my_url'];
$page_name = $instance['page_name'];
$message_lenght = $instance['message_lenght'];
//CONFIGS
// get user access_token
$token_url = 'https://graph.facebook.com/oauth/access_token?client_id='
. $app_id . '&redirect_uri=' . urlencode($my_url)
. '&client_secret=' . $app_secret
. '&grant_type=client_credentials';
// response is of the format "access_token=AAAC..."
$access_token = substr(file_get_contents($token_url), 13);
$fql_query_url = 'https://graph.facebook.com/v2.3/' . $page_id
. '/posts?access_token=' . $access_token;
$fql_query_result = file_get_contents($fql_query_url);
$fql_query_obj = json_decode($fql_query_result, true);
$data = $fql_query_obj['data'][0];
$img_query_url = 'https://graph.facebook.com/v2.3/' . $data['object_id'] . '/?access_token=' . $access_token;
$img_query_result = file_get_contents($img_query_url);
$img_query_obj = json_decode($img_query_result, true);
$msg = substr($data['message'], 0, $message_lenght). '... ';
if($img_query_obj['source'] == ""){
$img_url = $data[picture];
}else{
$img_url = $img_query_obj['source'];
}
//START APP
echo $before_widget;
if($title !== ""){
echo '<h3>'.$title.'</h3>';
}
?>
<div class="facebook-widget">
<pre class="hide"><?php var_dump($data[picture]); ?></pre>
<div class="img"><img src="<?php echo $img_url; ?>"></div>
<div class="text">
<div class="date">
FACEBOOK/
<?php echo date("m.d.Y", strtotime($data['updated_time'])); ?>
</div>
<a class="page_title" target="_blank" href="<?php echo $my_url; ?>">/<?php echo $page_name; ?></a>
<p><?php echo mb_substr($msg, 0, 95); ?>[...]<a href="<?php echo $data[link]; ?>" target="_blank"> (read more)</a></p>
</div>
<div class="facebookfollow">
<a class="facebook-fallow-button" href="<?php echo $my_url; ?>" target="_blank">Follow Us</a>
</div>
</div>
<?php
echo $after_widget;
Jak widać dodałem warunkowe oświadczenie aby sprawdzić, czy nie ma zdjęć z postu. $ img_query_obj ['source'] jest dla postów publikowanych w normalny sposób - trochę tekstu + upload obrazu, drugi - dla postów połączonych - uzyskać obraz 130x130 z zapytania danych, ponieważ nie ma obrazu w standardowy sposób.
Moje pytanie brzmi: jak uzyskać obraz postu, jeśli w odpowiedzi jest tylko obraz 130x130?
Pozdrowienia