Пример #1
0
function yinstagram_get_user_id($access_token, $username)
{
    $id = null;
    if ($username != 'self') {
        $responses = yinstagram_fetch_data('https://api.instagram.com/v1/users/search?q=' . $username . '&access_token=' . $access_token);
        $responses = json_decode($responses);
        if ($responses->meta->code == 200) {
            if (!empty($responses->data)) {
                $id = $responses->data[0]->id;
            }
        }
    }
    return $id;
}
Пример #2
0
function yinstagram_get_tags_images($access_token, $hashtags, $number_of_images = 1, $is_shortcode = true, $attr_hashtags = null)
{
    $tags = empty($attr_hashtags) ? yinstagram_extract_hashtags($hashtags) : yinstagram_extract_hashtags($attr_hashtags);
    $number_of_hashtags = count($tags);
    $count = round(33 / $number_of_hashtags);
    $output = array();
    foreach ($tags as $tag) {
        $responses = yinstagram_fetch_data('https://api.instagram.com/v1/tags/' . $tag . '/media/recent?access_token=' . $access_token . '&count=' . $count);
        $responses = json_decode($responses);
        if (isset($responses->data)) {
            $output = array_merge($output, $responses->data);
            $next_url = isset($responses->pagination->next_url) ? $responses->pagination->next_url : null;
            if ($is_shortcode) {
                $i = 0;
                while ($next_url) {
                    $responses = yinstagram_fetch_data($next_url);
                    $responses = json_decode($responses);
                    if (isset($responses->data)) {
                        $output = array_merge($output, $responses->data);
                        if ($i == $number_of_images) {
                            break;
                        }
                        $i++;
                        $next_url = $responses->pagination->next_url ? $responses->pagination->next_url : null;
                    }
                }
            }
        }
    }
    return yinstagram_shuffle_assoc($output);
}