简体   繁体   English

Ajax用户名和日期Instagram API

[英]Ajax username and date Instagram API

Currently, I'm trying to create a page using instagram's api, showing recent pictures with a specific tag, as well as the user who posted it and the date posted. 目前,我正在尝试使用instagram的api创建一个页面,以显示带有特定标签的最新图片以及发布该页面的用户和发布日期。 I'm also trying to have the infinite loading functionality, with ajax loading in more instagram posts as the page reaches the bottom. 我还尝试具有无限加载功能,随着页面到达底部,ajax会在更多instagram帖子中加载。

Heres a link to the live site http://www.laithazzam.com/work/nukes/indexnew.php 此处是指向实时网站http://www.laithazzam.com/work/nukes/indexnew.php的链接

Clicking the red yes will skip the video, and go straight to the instagram feed. 单击红色的是将跳过视频,并直接转到instagram feed。

I'm currently using Christian Metz's solution found here, https://gist.github.com/cosenary/2961185 我目前正在使用Christian Metz的解决方案, 网址为https://gist.github.com/cosenary/2961185

I am also having an issue with posting the date, in the first initial load, as well in the ajax loads. 在第一个初始加载以及ajax加载中发布日期时,我也遇到了问题。 I was previously able to use this following code, before trying to implement Christian's php/ajax solution. 在尝试实现Christian的php / ajax解决方案之前,我以前能够使用以下代码。

var date = new Date(parseInt(data.data[i].created_time) * 1000);
<p class='date'>"+(date.getMonth()+1)+"/"+date.getDate()+"/"+date.getFullYear()+"</p>

I guess what I don't understand, is how the ajax loading function, is actually functioning. 我想我不了解的是ajax加载功能实际上是如何运行的。 How would I also pull the name, and date through the ajax loading success function as well? 我还将如何通过ajax加载成功函数提取名称和日期?

$.ajax({
      type: 'GET',
      url: 'ajax.php',
      data: {
        tag: tag,
        max_id: maxid
      },
      dataType: 'json',
      cache: false,
      success: function(data) {
        // Output data
        $.each(data.images, function(i, src) {
        $("#instafeed").append('<img src="' + src + '">');
        });

        // Store new maxid
        $('#more').data('maxid', data.next_id);
      }
    });
  });

The data parameter of the success handler function is populated from whatever JSON ajax.php returns and the structure will match accordingly. success处理程序函数的data参数由返回的JSON ajax.php填充,并且结构将进行相应匹配。 It looks like the images attribute of that object only has an array of URLs for the images and no other data. 看起来该对象的images属性仅具有用于图像的URL数组,没有其他数据。

You'll need to update this section of the PHP script to return more than just the array of URLs for the images and also include the additional data retrieved from the Instagram API. 您将需要更新PHP脚本的这一部分,以返回不仅仅是图像URL的数组,还包括从Instagram API检索的其他数据。

Try updating the last part to this: 尝试将最后一部分更新为:

echo json_encode(array(
    'next_id' => $media->pagination->next_max_id,
    'images'  => $media->data
));

Then you'll have full access to all the media data, not just the URL. 然后,您将拥有对所有媒体数据的完全访问权,而不仅仅是URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM