/** * Execute the job. * * @return void */ public function handle() { $instagram = new Instagram(array('apiKey' => config('instagram.id'), 'apiSecret' => config('instagram.secret'), 'apiCallback' => 'http://instagram.app')); $account = InstagramAccount::find($this->id); $accountMedia = []; $user = $instagram->getUser($account['instagram_object_id']); if ($user->meta->code == 200) { $mediaCount = $user->data->counts->media; if ($mediaCount != 0) { $media = $instagram->getUserMedia($account['instagram_object_id'], 32); while (!is_null($media)) { foreach ($media->data as $data) { if ($data->type == 'video') { continue; } $accountMedia[] = new InstagramMedia(['instagram_object_id' => $data->id, 'photo_url' => $data->link, 'photo_caption' => is_object($data->caption) ? $data->caption->text : null, 'likes_count' => $data->likes->count, 'comments_count' => $data->comments->count]); } $media = $instagram->pagination($media, 32); } } else { $account->status = InstagramAccount::GRABBER_COMPLETED; $account->save(); } } DB::transaction(function () use($account, $accountMedia) { $account->InstagramMedia()->saveMany($accountMedia); $account->status = InstagramAccount::GRABBER_COMPLETED; $account->save(); }); }
function get_user_media(Instagram $instagram) { $userData = $instagram->getUser(); $userMedia = $instagram->getUserMedia('self'); $userLikes = $instagram->getUserLikes($userMedia); $userComments = $instagram->getUserComments($userMedia); $userTags = $instagram->getUserTags($userMedia); $data = array('userData' => $userData, 'userMedia' => $userMedia, 'userLikes' => $userLikes, 'userComments' => $userComments, 'userTags' => $userTags); if ($data) { return $data; } return false; }
/** * Execute the job. * * @return void */ public function handle() { $instagram = new Instagram(array('apiKey' => config('instagram.id'), 'apiSecret' => config('instagram.secret'), 'apiCallback' => 'http://instagram.app')); $account = InstagramAccount::find($this->id); $account->status = InstagramAccount::GRABBER_NOT_COMPLETED; $account->save(); $accountMedia = array_combine($account->instagramMedia->lists('instagram_object_id')->toArray(), $account->instagramMedia->all()); $user = $instagram->getUser($account['instagram_object_id']); if ($user->meta->code == 200) { $mediaCount = $user->data->counts->media; if ($mediaCount != 0) { $media = $instagram->getUserMedia($account['instagram_object_id'], 32); while (!is_null($media)) { foreach ($media->data as $data) { if ($data->type == 'video') { continue; } if ($this->mode == 'WITH_ADVANCED' && isset($accountMedia[$data->id])) { $accountMedia[$data->id]->instagramMediaLike()->save(new InstagramMediaLike(['count' => $data->likes->count - $accountMedia[$data->id]->likes_count])); $comments = $instagram->getMediaComments($data->id); if (!empty($comments->data)) { foreach ($comments->data as $comment) { $accountMedia[$data->id]->instagramMediaComment()->updateOrCreate(['instagram_object_id' => $comment->id], ['instagram_object_id' => $comment->id, 'created_at' => Carbon::createFromTimestamp($comment->created_time)]); } } } if (isset($accountMedia[$data->id])) { // update $accountMedia[$data->id]->photo_caption = is_object($data->caption) ? $data->caption->text : null; $accountMedia[$data->id]->likes_count = $data->likes->count; $accountMedia[$data->id]->comments_count = $data->comments->count; } else { // insert $accountMedia[] = new InstagramMedia(['instagram_object_id' => $data->id, 'photo_url' => $data->link, 'photo_caption' => is_object($data->caption) ? $data->caption->text : null, 'likes_count' => $data->likes->count, 'comments_count' => $data->comments->count]); } } $media = $instagram->pagination($media, 32); } } else { $account->status = InstagramAccount::GRABBER_COMPLETED; $account->save(); } } DB::transaction(function () use($account, $accountMedia) { $account->InstagramMedia()->saveMany($accountMedia); $account->status = InstagramAccount::GRABBER_COMPLETED; $account->save(); }); }
*/ require '../src/Instagram.php'; use MetzWeb\Instagram\Instagram; // initialize class $instagram = new Instagram(array('apiKey' => 'YOUR_APP_KEY', 'apiSecret' => 'YOUR_APP_SECRET', 'apiCallback' => 'YOUR_APP_CALLBACK')); // receive OAuth code parameter $code = $_GET['code']; // check whether the user has granted access if (isset($code)) { // receive OAuth token object $data = $instagram->getOAuthToken($code); $username = $username = $data->user->username; // store user access token $instagram->setAccessToken($data); // now you have access to all authenticated user methods $result = $instagram->getUserMedia(); } else { // check whether an error occurred if (isset($_GET['error'])) { echo 'An error occurred: ' . $_GET['error_description']; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Instagram - photo stream</title> <link href="https://vjs.zencdn.net/4.2/video-js.css" rel="stylesheet"> <link href="assets/style.css" rel="stylesheet">
<?php /***************************************** * Builds the image_data array /****************************************/ require HIPSTR_DIR . '/classes/Instagram.php'; use MetzWeb\Instagram\Instagram; // Get options $options = get_option('hipstr_options'); if (!empty($options['client_id']) && !empty($options['client_secret'])) { // Initialize class $instagram = new Instagram(array('apiKey' => $options['client_id'], 'apiSecret' => $options['client_secret'], 'apiCallback' => WEBSITE_URL)); // Build the image_data array if (!empty($options['token'])) { // Pass user access token to API $instagram->setAccessToken($options['token']); // Get the most recent media published by a user $media = $instagram->getUserMedia('self', 8); //Returns 8 entries for the logged in user // Create an array with just the links and img_urls $links = array(); $img_urls = array(); foreach ($media->data as $entry) { $link = $entry->link; array_push($links, $link); $img_url = $entry->images->standard_resolution->url; array_push($img_urls, $img_url); } $image_data = array_combine($links, $img_urls); } }
$insta = new Instagram(array('apiKey' => '41f65a5c684048bca797dbf0775c9ec7', 'apiSecret' => '95647e6ef2a445ff92e8b27c82bf8da6', 'apiCallback' => 'http://localhost/JSfaceLogin/Instagram/instagram.php')); if (isset($_GET['code'])) { echo $_GET['code']; $accessToken = $insta->getOAuthToken($_GET['code']); $insta->setAccessToken($accessToken); $token = $insta->getAccessToken() . '<br>'; print_r($accessToken); $id = $accessToken->user->id; echo $full_name = $accessToken->user->username; echo '<pre>'; echo '</pre>'; $imagen = $accessToken->user->profile_picture; echo '<img src="' . $imagen . '"/>'; echo $insta->getUserLikes(1)->data[0]->likes->count . "Me gusta"; $follow = $insta->getUserFollows(); print_r($insta->getUserMedia()); } else { // check whether an error occurred if (isset($_GET['error'])) { echo 'An error occurred: ' . $_GET['error_description']; } //print_r($insta->getUserLikes(1)); } ?> <!doctype html> <html> <body> <img src="instagram.ico" height="42" width="42" > <a src="instagram.ico" href = "<?php echo $insta->getLoginUrl(); ?>
public function adminAction() { // Nom du fichier $utility = $this->get('troiswa_back.util'); echo $utility->slugify('un éléphant bleu'); echo '<br>'; echo $utility->getText(); dump($utility); die; $file = __DIR__ . "/../../../../app/cache/cache_instagram.txt"; $fs = new Filesystem(); $timeCache = time() + 1 * 60; dump(date("F d Y H:i:s.", filemtime($file))); dump(date("F d Y H:i:s.", $timeCache)); die(dump($timeCache, filemtime($file))); clearstatcache(); // filemtime lit la date de dernière modification du fichier if ($fs->exists($file) && filemtime($file) > $timeCache) { // Récupération du contenu du fichier cacheinstagram $mesImages = unserialize(file_get_contents($file)); dump(file_get_contents($file)); dump($mesImages); die('Utilisation du cache'); } else { $instagram = new Instagram(array('apiKey' => $this->getParameter('client_id_instagram'), 'apiSecret' => $this->getParameter('client_secret_instagram'), 'apiCallback' => $this->getParameter('callback_instagram'))); $instagram->setAccessToken($this->getParameter('token_instagram')); $mesImages = $instagram->getUserMedia($this->getParameter('id_instagram')); // Création du fichier et ajout des minutes du cache $fs->touch($file, time() + $timeCache); // insertion dans le $fs->dumpFile($file, serialize($mesImages)); //die(dump($mesImages)); } // die(dump($mesImages)); //die(dump($instagram->getPopularMedia())); // foreach($instagram->getPopularMedia()->data as $media) // { // die(dump($media)); // echo "<img src='".$media->images->thumbnail->url."'>"; // die; // } $em = $this->getDoctrine()->getManager(); $productAll = $em->getRepository("TroiswaBackBundle:Product")->findAllPerso(); $products = $em->getRepository("TroiswaBackBundle:Product")->findNbProductByCategory(); return $this->render("TroiswaBackBundle:Main:admin.html.twig", ["prenom" => "Jean", "products" => $products, "instagram" => $mesImages]); }
} else { // check whether an error occurred if (isset($_GET['error'])) { echo 'An error occurred: ' . $_GET['error_description']; } } } // check authentication if ($token === false) { // authentication failed -> redirect to login header('Location: index.php'); } else { // store user access token $instagram->setAccessToken($token); // now we have access to all authenticated user methods $media = $instagram->getUserMedia(); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Instagram - photo stream</title> <link href="https://vjs.zencdn.net/4.2/video-js.css" rel="stylesheet"> <link href="assets/style.css" rel="stylesheet"> <script src="https://vjs.zencdn.net/4.2/video.js"></script> </head> <body> <div class="container"> <header class="clearfix">
<?php require_once 'vendor/Instagram.php'; use MetzWeb\Instagram\Instagram; $instagram = new Instagram('3bb0d19996d84c40a850d733d637ac3f'); echo json_encode($instagram->getUserMedia(426196477, 12));
function gl_instagram_latest($atts) { ob_start(); extract(shortcode_atts(array('user_id' => '', 'slider_posts' => ''), $atts)); ?> <div class="slider_section"> <div class="container"> <div class="holder_slider"> <h2 class="title_section">#GirlLane</h2> <div class="slider" id="instagramslider"> <?php $instagram = new Instagram('c9d7d83571be4716b3fbbfd1764945ad'); $result = $instagram->getUserMedia($user_id, $slider_posts); foreach ($result->data as $media) { // output media if ($media->type === 'video') { // video $image = $media->images->low_resolution->url; } else { // image $image = $media->images->low_resolution->url; } // create meta section $avatar = $media->user->profile_picture; $username = $media->user->username; $comment = !empty($media->caption->text) ? $media->caption->text : ''; ?> <div class="slide"> <img src="<?php echo $image; ?> " alt=""> <div class="hover_block"> <div class="user_info"> <div class="avatar"><img src="<?php echo $avatar; ?> " alt=""></div> <div class="name"> <span><?php echo $username; ?> </span> <span>@Girllane</span> </div> </div> <ul class="share_block"> <li><a href="#" class="share">Share</a></li> <li><a href="#" class="inst">Instagram</a></li> </ul> </div> </div> <?php } ?> </div> <?php $facebook = of_get_option('facebook'); $instagram = of_get_option('instagram'); $youtube = of_get_option('youtube'); ?> <ul class="social_block"> <?php if ($facebook) { ?> <li><a href="<?php echo $facebook; ?> " class="fb anim" target="_blank">facebook</a></li><?php } ?> <?php if ($instagram) { ?> <li><a href="<?php echo $instagram; ?> " class="inst anim" target="_blank">instagram</a></li><?php } ?> <?php if ($youtube) { ?> <li><a href="<?php echo $youtube; ?> " class="yt anim" target="_blank">youtube</a></li><?php } ?> </ul> </div> </div> </div> <?php $myvariable = ob_get_clean(); return $myvariable; }
$dataLink = ""; foreach ($item->likes->data as $itemLink) { //$dataLink .= '<a href="https://instagram.com/'. $itemLink->username. '" class="usuarios">' . $itemLink->username . "</a> "; $dataLink .= $itemLink->username . ", "; //$dataLinkArray[] = $itemLink->username; $a = array(); $a['nombre'] = $itemLink->username; $dataLinkArray[] = $a; } $data['dataLink'] = $dataLink; $data['dataUser'] = $dataLinkArray; $data['likes'] = $item->likes->count; $data['created_time'] = $item->created_time; $dataTotal[] = $data; } $mediaUser = $instagram->getUserMedia('1133961085'); foreach ($mediaUser->data as $item) { //print_r($item); $data = array(); $data['image_link'] = $item->images->standard_resolution->url; if (!empty($item->caption)) { $data['caption'] = $item->caption->text; } else { $data['caption'] = ''; } if (!empty($item->user)) { $data['user'] = $item->user->username; $data['userPicture'] = $item->user->profile_picture; } else { $data['user'] = ''; $data['userPicture'] = '';
public static function set_instagram_cache() { $instagram_ids = array(25877499); require_once 'InstagramAPIExchange.php'; require_once 'InstagramException.php'; $instagram = new Instagram('03159bdd94b14ac1803d1945b6d9c759'); $instagram->setAccessToken('25877499.1677ed0.bad6959f2be14f9da744d1c0b9f81f26'); $all_instas = array(); foreach ($instagram_ids as $id) { $all_instas = array_merge($instagram->getUserMedia($id, 5)->data, $all_instas); } if (!isset($all_instas[0]->created_time)) { return false; } set_transient('instas_time', time(), 60 * 60); // store for 1 hour (it gets deleted anyways) set_transient('instas', $all_instas, 60 * 60); // store for 1 hour (it gets deleted anyways) return $all_instas; }
public function widget($args, $instance) { $title = $instance['title']; $limit = $instance['limit']; $user_id = $instance['user_id']; $client_id = $instance['client_id']; $background = $instance['background']; $size = '50%'; require get_template_directory() . '/inc/Instagram.php'; $instagram = new Instagram($client_id); $result = $instagram->getUserMedia($user_id, $limit); if ($result) { echo $args['before_widget']; echo "<div class='instagram__wrap' style='background:" . $background . "'>"; if (!empty($title)) { echo $args['before_title'] . $title . $args['after_title']; } foreach ($result->data as $media) { echo '<div class="image_instagram"><a href="' . $media->link . '" target="_blank">'; echo "<img src='" . $media->images->low_resolution->url . "' />"; //height='".$size."' width='".$size."' echo '</a><a href="' . $media->link . '" target="_blank"><div class="image_popup"></div></a></div>'; } echo "</div>"; echo $args['after_widget']; } }
* * @link https://github.com/cosenary/Instagram-PHP-API * @author Christian Metz * @since 4.04.2014 */ if (file_exists($_SERVER['HOME'] . '/rolle.wtf/vendor')) { include $_SERVER['HOME'] . '/rolle.wtf/vendor/autoload.php'; } else { include $_SERVER['HOME'] . '/rolle.wtf.deploy/vendor/autoload.php'; } use MetzWeb\Instagram\Instagram; $instagram = new Instagram('YOUR_API_KEY'); // User ID (find your ID: http://otzberg.net/iguserid) $userID = YOUR_USER_ID; // Get the most recent public media published by the user $media = $instagram->getUserMedia($userID, 1); foreach ($media->data as $data) { ?> <header class="item-header" style="background-image: url('<?php echo $data->images->low_resolution->url; ?> ');"> <div class="shade"></div> <p>Last Instagram photo taken <?php echo aika(abs(strtotime(date('d.m.Y H:i', $data->caption->created_time))), time() + 60); ?> ago.</p> </header>
public function adminAction() { /*dump($this->getDoctrine()->getManager()); dump($this->getDoctrine()->getManager()); die;*/ /*$utility = $this->get('wa_back.util'); echo $utility->slugify('salut ludo'); dump($utility); die;*/ //Doctrine pour gérer des bbd != //Manager pour gérer des bundles != $em = $this->getDoctrine()->getManager(); //AFFICHER TOUT LES PRODUITS $productAll = $em->getRepository("WaBackBundle:Produit")->findAllPerso(); //AFFICHER UN PRODUIT $product = $em->getRepository("WaBackBundle:Produit")->findPerso(14); //AFFICHER LES PRODUITS PAR CATEGORIE $productCatHome = $em->getRepository("WaBackBundle:Produit")->pdtWithCatHome(1); //AFFICHER LES $pdtSansCat = $em->getRepository("WaBackBundle:Produit")->pdtSansCategorie(); //AFFICHER LE NBR DE PRODUITS PAR CATEGORIE $nbrPdtByCat = $em->getRepository("WaBackBundle:Produit")->nbrPdtByCat(); //AFFICHER LE PRODUIT LE PLUS CHER $pdtPrixMax = $em->getRepository("WaBackBundle:Produit")->pdtPrixMax(); //AFFICHER LES CATEGORIES SANS IMAGES $catSansImg = $em->getRepository("WaBackBundle:Categorie")->catSansImg(); //UTILISER L'APPLI INSTAGRAM // Chemin ou on crée le fichier $file = __DIR__ . "/../../../../app/cache/cache_instagram.txt"; $fs = new Filesystem(); //Timestamp du cache $timeCache = time() - 1 * 60; //On vérifie qu'on a fait un cache d'1 min avec un dump //dump(date ("F d Y H:i:s.", filemtime($file))); //dump(date ("F d Y H:i:s.", $timeCache)); //die(dump($timeCache, filemtime($file))); //Si le fichier existe et que le temps d'utilisation de la dernière modif du fichier > timestamp //prévu dans le cache clearstatcache(); if ($fs->exists($file) && filemtime($file) > $timeCache) { //On récupère le contenu du fichier cacheinsta $mesImages = unserialize(file_get_contents($file)); //die('cache'); } else { //die(dump($this->getParameter('client_id_instagram'))); $instagram = new Instagram(array('apiKey' => $this->getParameter('client_id_instagram'), 'apiSecret' => $this->getParameter('client_secret_instagram'), 'apiCallback' => $this->getParameter('callback_instagram'))); //Récupérer le token après le code= //die(dump($instagram->getLoginUrl())); $instagram->setAccessToken($this->getParameter('token_instagram')); //die(dump($instagram->getPopularMedia())); $mesImages = $instagram->getUserMedia($this->getParameter('id_instagram')); //Mettre les infos dans le fichier //Création du fichier $fs->touch($file); //Mettre les images dans le fichier $fs->dumpFile($file, serialize($mesImages)); //dump(file_get_contents($file)); //dump($mesImages); //die('Utilisation du cache'); } //die(dump($mesImages)); //Parcourir l'objet et afficher ce qu'on veut /*foreach($instagram->getPopularMedia()->data as $media) { //die(dump($media)); echo "<img src='".$media->images->thumbnail->url."'>"; //die; }*/ return $this->render('WaBackBundle:Main:admin.html.twig', ['productAll' => $productAll, 'productDetail' => $product, 'productAccueil' => $productCatHome, 'productSansCat' => $pdtSansCat, 'nbrPdtByCat' => $nbrPdtByCat, 'pdtPrixMax' => $pdtPrixMax, 'catSansimage' => $catSansImg, 'instagram' => $mesImages]); }
$sqlUser = "******"; $select = mysqli_query($con, $sqlUser) or die("Error inserting user '{$username}': " . mysqli_error($con) . "<br>{$sqlUser}"); while ($row = mysqli_fetch_array($select)) { $user = $instagram->getUser($row['IG_UserID']); $id = $user->data->id; $username = $user->data->username; $bio = urlencode($user->data->bio); $profpic = $user->data->profile_picture; $fullname = $user->data->full_name; $posts = $user->data->counts->media; $followers = $user->data->counts->followed_by; $following = $user->data->counts->follows; $sql = "INSERT INTO `UserData`(`IG_UserID`, `NoFollowers`, `NoFollowing`, `NoPosts`, `Created_at`) VALUES ({$id}, {$followers}, {$following}, {$posts}, NOW())"; mysqli_query($con, $sql) or die("Error inserting user '{$username}': " . mysqli_error($con) . "<br>{$sql}"); echo "{$sql};<br>"; $posts = $instagram->getUserMedia($id, 1000); foreach ($posts->data as $media) { $postid = $media->id; $TagCount = count($media->tags); if ($TagCount > 0) { $sqlTagCheck = "SELECT COUNT(ID) FROM Tags WHERE PostID = '{$postid}'"; $tagcheck = mysqli_query($con, $sqlTagCheck) or die("Error checking for '{$postid}' tags: " . mysqli_error($con) . "<br>{$sqlTagCheck}"); $tagcheck = mysqli_fetch_array($tagcheck); $count = $tagcheck[0]; if ($count == 0) { foreach ($media->tags as $tag) { $sqlTagInsert = "INSERT INTO `Tags`(`Tag`, `PostID`, `Created_at`) VALUES ('{$tag}', '{$postid}', NOW())"; mysqli_query($con, $sqlTagInsert) or die("Error inserting tag '{$tag}': " . mysqli_error($con) . "<br>{$sqlTagInsert}"); // echo "$sqlTagInsert;<br>"; } }