FacebookのグラフAPIからアルバム写真を取得しています。
このコードはうまくいきますが、130 以上の幅:130 x 高さ:130 の最小のサムネイルを選択しようとしています。
つまり、幅と高さの合計ではなく、幅または高さが 130 以上である必要があります。
注:配列リストは facebooks アルバムからの画像のバリエーションであるため、比例します。したがって、ポートレートまたはランドスケープの寸法である場合、それに応じて寸法が調整されます。
したがって、print_r
以下から、最初の配列の項目 (2) がその説明に適合することがわかりますが、これは幅/高さが 130 を超える最小であるため、他の配列は数値 (2) と (1) になります。
$userURL2 = "https://graph.facebook.com/$albumID/photos?access_token=" . $fb_oAuth_token;
$ch2 = curl_init($userURL2);
curl_setopt($ch2, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
$data2 = curl_exec($ch2);
curl_close($ch2);
$pictures = json_decode($data2, true);
print_r($pictures);
からの出力print_r($pictures);
Array
(
[0] => Array
(
[height] => 288
[width] => 460
[source] => https://myurl.jpg
)
[1] => Array
(
[height] => 200
[width] => 320
[source] => https://myurl.jpg
)
[2] => Array
(
[height] => 130
[width] => 180
[source] => https://myurl.jpg
)
[3] => Array
(
[height] => 81
[width] => 130
[source] => https://myurl.jpg
)
)
Array
(
[0] => Array
(
[height] => 500
[width] => 500
[source] => https://myurl.jpg
)
[1] => Array
(
[height] => 500
[width] => 500
[source] => https://myurl.jpg
)
[2] => Array
(
[height] => 480
[width] => 480
[source] => https://myurl.jpg
)
)
Array
(
[0] => Array
(
[height] => 335
[width] => 300
[source] => https://myurl.jpg
)
[1] => Array
(
[height] => 335
[width] => 300
[source] => https://myurl.jpg
)
)
質問: これを php でどのように記述しますか?
foreach($pictures['data'] as $picture){
$width = $picture['width'];
$height = $picture['height'];
// choose the smallest [source] above width:130 x height:130
}