Exemplo n.º 1
2
 public function instagram()
 {
     $id = '1600192808';
     set_time_limit(0);
     ini_set('memory_limit', '-1');
     ini_set('max_execution_time', '999999');
     require APPPATH . 'third_party/Instagram/Instagram.php';
     require APPPATH . 'third_party/Instagram/InstagramException.php';
     $config = '2440e15f188a41439c6edcd698ff081f';
     $instagram = new Instagram($config);
     $response = $instagram->getUserMedia($id);
     while ($response && count($response->data)) {
         if ($response->meta->code != 200) {
             print_r($response);
             exit;
         }
         $items = $response->data;
         foreach ($items as $item) {
             if (!isset($item->images->standard_resolution->url)) {
                 continue;
             }
             $link = $item->link;
             $sql = "select * from instagram where link = '{$link}'";
             $row = $this->db->query($sql)->row();
             if ($row) {
                 die('FINISH');
             }
             $file = str_replace(array('https://instagram.com/p/', '/'), '', $link) . '.jpg';
             $folder = 'instagram/';
             $url = $item->images->low_resolution->url;
             copy($url, FCPATH . 'files/' . $folder . $file);
             $this->db->insert('nz_file', array('id_folder' => 28, 'id_type' => 1, 'file' => $folder . $file, 'name' => $file, 'alt' => '', 'id_user' => 1, 'deleted' => 0, 'date' => date('Y-m-d H:i:s')));
             $idf = $this->db->insert_id();
             $this->db->insert('instagram', array('id_file' => $idf, 'link' => $link));
         }
         $response = $instagram->pagination($response);
     }
 }
Exemplo n.º 2
0
function smamo_instagram()
{
    // Klargør svar
    $response = array();
    $num = isset($_POST['num']) ? 4 * wp_strip_all_tags($_POST['num']) : 4;
    // vi skal bruge et hashtag, ellers die();
    if (!isset($_POST['hash'])) {
        $response['code'] = '400';
        $response['error'] = 'No hashtag received';
        wp_die(json_encode($response));
    }
    // Indstil $tag
    $tag = wp_strip_all_tags($_POST['hash']);
    // Inkluder instagram class
    require get_template_directory() . '/functions/instagram/instagram.class.php';
    // Opret ny instance
    $instagram = new Instagram(array('apiKey' => 'dd36cc7a7be445c8a00d9f383e49f8c8', 'apiSecret' => 'e750735ffba74f8a8ed753a33c7351da', 'apiCallback' => 'http://faaborg-gym.dk'));
    $response['images'] = array();
    $inst_obj = $instagram->getTagMedia($tag, $num);
    $next_page = $instagram->pagination($inst_obj);
    $response['next'] = $next_page;
    foreach ($inst_obj->data as $key => $val) {
        $response['images'][] = $val;
    }
    wp_die(json_encode($response));
}