Created
April 8, 2020 02:26
-
-
Save quangpro1610/27ebb66b55a4739b1f5a75980d3a9684 to your computer and use it in GitHub Desktop.
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 | |
header('Content-Type: text/html; charset=utf-8'); | |
$url = file_get_contents('https://api.tumblr.com/v2/blog/gaixinhchonloc.com/posts/photo?api_key=OAuth_Consumer_Key'); | |
$json = json_decode($url, true); | |
$json_posts = $json['response']['posts']; | |
$data = array(); | |
foreach ($json_posts as $key => $value) { | |
$data[] = $value['photos'][0]['original_size']['url']; | |
} | |
function array_random($array, $amount = 1){ | |
$keys = array_rand($array, $amount); | |
if ($amount == 1) { | |
return $array[$keys]; | |
} | |
$results = []; | |
foreach ($keys as $key) { | |
$results[] = $array[$key]; | |
} | |
return $results; | |
} | |
$link_img = array_random($data); | |
$result = array( | |
'messages' => array( | |
'0' => array( | |
'attachment' => array( | |
'type' => 'image', | |
'payload' => array( | |
'url' => $link_img | |
) | |
) | |
), | |
) | |
); | |
echo json_encode($result, JSON_UNESCAPED_UNICODE); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment