Load more than 12 Pictures Instagram API/PHP

Status
Not open for further replies.

davidmedia

Junior Member
Joined
Aug 7, 2013
Messages
138
Reaction score
59
Hey guys,
i need your help!
I have a script that loads maximum 12 Pictures if user types in his username. Then he can select pictures...
But my Script only loads 12 Pictures MAXIMUM. I dont know how to let him load more than 12 because i need that URGEND! Other Websites have the same "style" of script but they can load more than 12. They have a load more button and then they load up more...
How do i realize that? Can someone private message me i send you the code and u try?

See pictures
 

Attachments

  • a25.PNG
    a25.PNG
    390.8 KB · Views: 426
  • step1.PNG
    step1.PNG
    32.4 KB · Views: 345
I can send u on private message but i cant Write u a private message
 
I cant post code. So whats up with this forum if someone cant post what they need to post and if someone cant communicate? So annoying!!
 
I added 25 to the count+25
See if that works .

The code pulling the info from the count of the users images and id of there account .

All I done was ask for exstera 25 more ...

Code:
                <?php

                       $select_image = get_post_meta( $product_id, 'like_image', true );

                       $count=0;

                       foreach($imagess as $imagede){

                         $img=$imagede['image'];

                         $link=$imagede['link'];

                        

                       // echo '<img src='."'$img'".' class="image-class img-check"><input type="checkbox" name="select_images[]" value='."'$link'".'>';                      

                        ?>

                        <li class="ig-label"><input type="checkbox" class="cbox" name="select_images[]" id="cb<?php echo $count; ?>" value="<?php echo $link; ?>" />

                          <label for="cb<?php echo $count; ?>"><img src="<?php echo $img; ?>" />

                          <p class="ig-meta">

                            <span class="ig-likes"><?php echo $imagede['like']; ?> likes</span>

                            <span class="ig-comments"><?php echo $imagede['comment']; ?> comments</span>

                            <span class="ig-views"></span>

                            <span class="ig-instruct">Click to select</span>

                          </p>

                          </label>

                        

                        </li>

                    <?php   $count+25; } ?>
 
JSON response have only last 12 images, so I doubt that would work.
 
JSON response have only last 12 images, so I doubt that would work.
So what will work then?

Should of had a set session in there so user can pic number of images so the count is that amount stupid code
 
Last edited by a moderator:
That code is pretty limited, but you have to grab end_cursor from json response, and request next page of images. Looking how to do it.
 
That code is pretty limited, but you have to grab end_cursor from json response, and request next page of images. Looking how to do it.
I re wrote it in PHP tested it but like you say the Jason crap need rewriting so I gave up .

To early for me and I hate coding

Why not use the jquary plugin so easy dam code
 
Hi
You need to use the pagination
1. Load first 12 posts instagram.com/design.bot/?__a=1
2. Load prev 12 posts through instagram.com/design.bot/?__a=1&max_id=1697371457784291576 where max_id is id of last loaded post in media -> nodes
May be it will help you
Sorry for my English
 
Hi
You need to use the pagination
1. Load first 12 posts instagram.com/design.bot/?__a=1
2. Load prev 12 posts through instagram.com/design.bot/?__a=1&max_id=1697371457784291576 where max_id is id of last loaded post in media -> nodes
May be it will help you
Sorry for my English

You mean like this

$('#easyPaginate').easyPaginate( paginateElement: 'img'
elementsPerPage:
effect: 'climb'});
 
  1. $('#easyPaginate').easyPaginate({
  2. paginateElement: 'img',
  3. elementsPerPage: 3,
  4. effect: 'climb'
  5. });
 
PHP:
<?php
/**
 * Template Name: order instagram like Template
 * A full-width template.
 *
 * @package Avada
 * @subpackage Templates
 */
get_header();
// Do not allow directly accessing this file.
if ( ! defined( 'ABSPATH' ) ) {
    exit( 'Direct script access denied.' );
}
error_reporting(0);
 if(isset($_REQUEST['instagram'])){
     //$uname='business_mafia';
      $uname=$_REQUEST['username'];
      $username=strtolower(str_replace(' ','_',$uname));
      $url="https://www.instagram.com/$username/?__a=1";
      $userinfo = file_get_contents($url);
      $userdata = json_decode($userinfo,true);
      $user=$userdata['user'];
      $iteration_url = $url;
      if(!empty($user)){
          $followers=$user['followed_by']['count']; echo '</br>';
          $follow=$user['follows']['count']; echo '</br>';
          $fullname= $user['full_name']; echo '</br>';
           $usernamee=$user['username']; echo '</br>';
          $profilepic=$user['profile_pic_url_hd'];
          $limit = 25;
          $tryNext = true;
          $found = 0;
          $images_all = array();
          while ($tryNext) {
              $tryNext = false;
              
              $remote = file_get_contents( $iteration_url );
              
              $response = $remote;
      
              if ($response === false) {
                  return false;
              }
              $data = json_decode($response, true);
              
              if ( $data === null) {
                  return false;
              }
              $media = $data['user']['media'];
      
              foreach ( $media['nodes'] as $index => $node ) {
                  if ( $found + $index < $limit ) {
                      if (isset($node['is_video']) && $node['is_video'] == true) {
                          $type = 'video';
                      } else {
                          $type = 'image';
                      }
                      $image = array(
                          'link' => 'https://instagram.com/p/' . $node['code'],
                          'comments' => $node['comments']['count'],
                          'likes' => $node['likes']['count'],
                          'thumbnail' => $node['thumbnail_src'],
                          'small' => $node['thumbnail_src'],
                          'full' => $node['display_src'],
                          'original' => $node['display_src']
                      );
                      array_push($images_all, $image);
                  }
              }
      
              $found += count($media['nodes']);
      
      
              if ( $media['page_info']['has_next_page'] && $found < $limit ) {
                  $iteration_url = $url . '&max_id=' . $media['page_info']['end_cursor'];
                  $tryNext = true;
              }
          }
          $massage="success";
        
 
      } else{
          //echo 'User name does not exite';
          $massage='error';
      }
    }
 
  global $woocommerce; 
  $product_id=$_REQUEST['add-to-cart'];
?>

<div class=" order-container" style="">
    <div>
        <div class="row order-row">
            <div class="col-sm-8 col-xs-12 order-left">
                <div class="order-title">Order Form</div>
                <div class="order-left-wrap">
                    <form id="follower" data-toggle="validator" method="post" <?php if($massage=='success'){ echo "style='display:none'"; } ?> >
                        <div class="form-group">
                            <label for="username" id="ask_label">Instagram Username *</label>
                            <input type="text" name="username" class="form-control required name" id="username"  placeholder="Please enter your Instagram username" required>
            <?php if($massage=='error'){ ?>  <p class="form-val" style="display: block;">Please enter valid instagram username. OR Instagram user have to be Public</p> <?php } ?>
                        </div>
                        <div class="form-group">
                            <label for="email">Email Address *</label>
                            <input type="email" autocapitalize="none" name="email" class="form-control" id="email" placeholder="Please enter your email address." required>
                          
                        </div>
                        <br>
                        </br>
                  
                        <button type="submit" name="instagram" class="btn btn-primary btn-lg crv-btn" id="devam" >
                        Continue &gt;
                        </button>
                    </form>
                    <!-- user details and payment details -->
                    <div id="followers" style="<?php if($massage=='success'){ echo 'display:flex'; }else { echo 'display:none'; }  ?> ">
                        <div class="follower-img">  <img class="follower-img-inner" src="<?php echo $profilepic; ?>"></div>
                        <div class="follow-info">
                            <h1><?php echo $usernamee; ?></h1>
                            <h2><?php echo $fullname; ?></h2>
                            <p id="follows">Following : <span><?php echo $follow; ?></span></p>
                            <p id="following">Followers : <span><?php echo $followers; ?></span></p>
                            <!--<p id="media-count">Media : <span>11</span></p> -->
                        </div>
                        <p class="follow-warn"></p>
                      
                    </div>
                            </script>
      
                    <script>
                        jQuery(document).ready(function($) {
 
                            $(".cbox").on("click", function() {
                                var numberOfChecked = $('input.cbox:checkbox:checked').length;
                                var totalimg=$('#totalimg').val();
                                if (numberOfChecked > totalimg) {
                                    $(this).prop('checked', false);
                                }
                            });
 
                        });
                        </script>
          
        <?php  if($massage=='success'){ ?>
        <form name="checkout" method="post" class="checkout woocommerce-checkout" action="<?php echo esc_url( wc_get_checkout_url() ); ?>" enctype="multipart/form-data">
        <div class="col-1">
        <input type="hidden" name="usernameinst" value="<?php echo $usernamee; ?>" />
            <div class="image-like" >
                    <ul>
                     <?php
                       $select_image = get_post_meta( $product_id, 'like_image', true );
                       $count=0;
                       foreach($images_all as $imagede){
                         $img=$imagede['original'];
                         $link=$imagede['link'];
                        
                       // echo '<img src='."'$img'".' class="image-class img-check"><input type="checkbox" name="select_images[]" value='."'$link'".'>';                       
                        ?>
                        <li class="ig-label"><input type="checkbox" class="cbox" name="select_images[]" id="cb<?php echo $count; ?>" value="<?php echo $link; ?>" />
                          <label for="cb<?php echo $count; ?>"><img src="<?php echo $img; ?>" />
                          <p class="ig-meta">
                            <span class="ig-likes"><?php echo $imagede['like']; ?> likes</span>
                            <span class="ig-comments"><?php echo $imagede['comment']; ?> comments</span>
                            <span class="ig-views"></span>
                            <span class="ig-instruct">Click to select</span>
                          </p>
                          </label>
                        
                        </li>
                    <?php   $count++; } ?>
                    <input type="hidden" id="totalimg" value="<?php echo $select_image; ?>" />
                    </ul>
                  
                    <i class="fa fa-heart fa-2x" aria-hidden="true" ></i><span class="select-image"> You can split likes on <?php echo $select_image; ?> Pictures
                    </span>
                    </div>
            <div class="woocommerce-billing-fields avada-select">
                <h3 class="row-title" data-fontsize="18" data-lineheight="25"></h3>
                    <div class="theme_box">
                        <div class="row">
                        
                        </div>
 
            </div><!--/ .theme_box-->
 
            </div>
        </div>
 
 
            <div id="order_review" class="woocommerce-checkout-review-order">
                <?php do_action( 'woocommerce_checkout_order_review' ); ?>
            </div>
        </form>
      
        <?php } ?>
                  
                </div>
                </div>
                <div class="col-sm-4 order-right">
                <div class="order-title detay-title">Order Details</div>
                <div class="order-right-wrap">
                <ul class="list-group">
                <li class="i order_ozellik"><img class="check_png lazyloaded" src="../wp-content/uploads/2018/01/check.png" data-was-processed="true"><?php echo get_the_title($product_id); ?></li>
                 <?php //echo  get_post($product_id)->post_content; ?>
                 <li><img class="check_png lazyloaded" src="../wp-content/uploads/2018/01/check.png">High Quality Likes</li>
                <li><img class="check_png lazyloaded" src="../wp-content/uploads/2018/01/check.png">All Real &amp; Active</li>
                <li><img class="check_png lazyloaded" src="../wp-content/uploads/2018/01/check.png">100% Safe</li>
                <li><img class="check_png lazyloaded" src="../wp-content/uploads/2018/01/check.png">No Password Required</li>
                <li><img class="check_png lazyloaded" src="../wp-content/uploads/2018/01/check.png">Instant Delivery</li>
                <li><img class="check_png lazyloaded" src="../wp-content/uploads/2018/01/check.png">24/7 Support</li>
                </ul>
                <ul class="summer"><li class="list-group-item">Total: <span><?php echo $total=$woocommerce->cart->get_cart_subtotal(); ?></span></li></ul></div>
            </div>
            </div>
      
    </div>
</div>
 
<?php get_footer(); ?>
 
Last edited:
Rimvy. I am really thankful that u and the other try to solve my problem.
In your rewritten code there loads more than 12 pictures but the 12 are repeating...

And can u put a button that loads more pictures? Show 12 and load more button to load the next 12?

New Pastebin Link https://pastebin.com/33c7md8C

Here is the CSS code of the PhP Script: https://pastebin.com/UtpYJJ6S
 

Attachments

  • wf2.PNG
    wf2.PNG
    659.8 KB · Views: 244
Last edited:
Status
Not open for further replies.
Back
Top