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)); }
public function InstaTagMedia($tag = false, $num = false, $shuffle = true) { $instagram = new Instagram(array('apiKey' => $this->InstagramApiKey, 'apiSecret' => $this->InstagramApiSecret, 'apiCallback' => $this->InstagramApiCallback)); $media = false; $output = false; $out = array(); if (!$tag) { $tag = $this->InstagramSearchTerm; } if (!$num) { $num = $this->InstagramItemsCount; } try { $media = $instagram->getTagMedia($tag, 50); } catch (Exception $e) { SS_Log::log(new Exception(print_r($e, true)), SS_Log::ERR); } if (is_object($media) && isset($media->data)) { foreach ($media->data as $data) { if (is_object($data)) { $item = array('caption' => $data->caption ? $data->caption->text : "", 'thumb' => $data->images->thumbnail->url, 'image' => $data->images->standard_resolution->url, 'username' => $data->user->username); array_push($out, $item); } } if ($shuffle) { shuffle($out); } $output = ArrayList::create($out); $output = $output->limit($num); } return $output; }
<?php $items = Instagram::getTagMedia($region['greeklish'], 20); if (count($items->data) == 0) { $items = Instagram::getTagMedia('greece', 20); } $i = 0; ?> <div id="carouselFull" class="carousel slide" data-ride="carousel"> <div class="carousel-inner"> @foreach ($items->data as $image) <div class="item {{( $i >= 1) ? '': 'active'}}" style="height: 340px;"> <img src="{{ $image->images->standard_resolution->url }}" width="614.5" height="368" alt="First slide"> <div class="container"> <div class="carousel-caption"> </div> </div> </div> <?php $i++; ?> @endforeach </div> <a class="left carousel-control" href="#carouselFull" role="button" data-slide="prev"><span class="fa fa-chevron-left"></span></a> <a class="right carousel-control" href="#carouselFull" role="button" data-slide="next"><span class="fa fa-chevron-right"></span></a> </div>
<?php // Get class for Instagram // More examples here: https://github.com/cosenary/Instagram-PHP-API require_once 'lib/instagram.class.php'; // Initialize class with client_id // Register at http://instagram.com/developer/ and replace client_id with your own $instagram = new Instagram(array('apiKey' => '6ffb1036a193401ca901270833b0b905', 'apiSecret' => 'c6c9139856ab474ba1c8d74fe97b7b10', 'apiCallback' => 'http://localhost')); // Set keyword for #hashtag $tag = 'kisschoice'; // Get latest photos according to #hashtag keyword $media = $instagram->getTagMedia($tag); // Set number of photos to show $limit = 5; // Set height and width for photos $size = '100'; echo json_encode($media->data); /* // Show results // Using for loop will cause error if there are less photos than the limit foreach(array_slice($media->data, 0, $limit) as $data) { // Show photo echo '<p><img src="'.$data->images->thumbnail->url.'" height="'.$size.'" width="'.$size.'" alt="SOME TEXT HERE"></p>'; }*/
$sql .= " ORDER BY created_at desc"; $sql .= " LIMIT 1"; $since_id = '0'; $stmt = $DBH->prepare($sql); $stmt->execute(); if ($stmt->rowCount() > 0) { while ($row = $stmt->fetch(PDO::FETCH_OBJ)) { $since_id = (int) $row->post_id; } } echo "\n\n" . SITE_TITLE . " Instagram EXTRACT \n\n"; $totalcount = 0; //foreach ($terms as $term) { // Instagram object $instagram = new Instagram(IG_CLIENT_ID); $result = $instagram->getTagMedia(TERM1, $since_id); // $count = 0; // cycle through data foreach ($result->data as $media) { $not_valid = FALSE; //$blocked = FALSE; $tags = $media->tags; $link = $media->link; $text = isset($media->caption->text) ? $Func->sanitize($media->caption->text) : ''; $created_at = date('Y-m-d H:i:s', $media->created_time); $created_date = date('Y-m-d', $media->created_time); $created_time = date('H:i:s', $media->created_time); $screen_name = $Func->sanitize($media->user->username); $post_id = $Func->sanitize($media->id); $user_id = $Func->sanitize($media->user->id); if (!in_array(TERM2, $tags)) {
echo ' height="480">'; echo '</iframe>'; // echo Twitter::linkify($tweet), // '<br/><a href=', // Twitter::linkTweet($tweet), '>', // Carbon\Carbon::createFromFormat('D M d H:i:s P Y', // $tweet->created_at), // '</a><br/><br/>'; } return 'thujohn/twitter'; }); /** * Registers the GET route to the vinkla/instagram package test page. */ Route::get('/instagram/vinkla', function () { $tag_media = Instagram::getTagMedia('taylorswift', 50); dump($tag_media); echo '<h1>Tag Media</h1>'; foreach ($tag_media->data as $media) { echo '<iframe class="instagram-media" '; echo ' src="', $media->link, 'embed/captioned/"'; echo ' frameborder="0"'; echo ' height="480">'; echo '</iframe>'; // echo $media->caption ? $media->caption->text : '', // '<br/><a href=', // $media->link, '>', // Carbon\Carbon::createFromTimestamp($media->created_time), // '</a><br/><br/>'; } $popular_media = Instagram::getPopularMedia();
error_reporting(E_ALL ^ E_NOTICE); if (empty($_GET['tag'])) { die('The hashtag is required'); } //Include Configuration $tag = str_replace('#', '', $_GET['tag']); $count = $_GET['count']; if ($count == "" || $count <= 0) { $count = 20; } require_once 'instagram.class.php'; // Initialize class with client_id // Register at http://instagram.com/developer/ and replace client_id with your own $instagram = new Instagram($client_ID); // Get latest photos according to #hashtag keyword $media = $instagram->getTagMedia($tag, $count); $count = 0; $json_format = '{"responseData": {"feed":{"feedUrl": "http://' . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"] . '","title":"Instagram / ' . $tag . '","link":"http://instagram.com/tags/' . $username . '","author":"","description":"Instagram updates from ' . $tag . ' / ' . $username . '.","type":"rss20","entries":['; if (is_array($media->data)) { foreach ($media->data as $row) { if ($count > 0) { $json_format .= ','; } $attached = ""; $attached .= ' <img alt="" src="' . $row->images->standard_resolution->url . '" /> '; $json_format .= '{"title":' . json_encode($row->caption->text) . ',"link":"' . $row->link . '","author":"' . $row->user->username . '","publishedDate":"' . date("D, d M Y H:i:s O", $row->created_time) . '","contentSnippet":' . json_encode($row->caption->text . $attached) . ',"content":' . json_encode($row->caption->text . $attached) . ',"categories":[]}'; $count++; } } $json_format .= ']}}, "responseDetails": null, "responseStatus": 200}'; header("Content-Type: application/json; charset=UTF-8");
/** * Searches Instagram for the specified hashtag $term. * * @example array($insta1, $insta2, $insta3) * @param string $term hashtag term to search for * @return array|object */ protected function searchInstagram($term) { $search_results = \Instagram::getTagMedia($term, 50); return $search_results->data; }