justb3a

Module: Instagram Feed

Recommended Posts

Ahhhh, you know what it could be! I am currently using hosts file to point a domain to another IP address so the rediercts url will be hitting a different server!

Do you think that is it?

Is there any work around whilst I'm in development to get this working on the server I am on?

Share this post


Link to post
Share on other sites

I keep getting the following error - [InstagramFeed]: No user '' was found. However it's working fine. 

Share this post


Link to post
Share on other sites

@justb3a Is it only possible to retrieve the recentMedia of the sandbox user?
EDIT: To clarify: Can I just access images of the access token user or can I get images from every user?

I get the images of my own account (which is in sandbox mode) but if I enter something diffent in the field "Username" in the modules settings, I still get the same images and not the images of the other user.

I even tried

$instagram = $modules->get('InstagramFeed')->getRecentMedia("cocacola");

but still my own images appear. I also tried clearing the cache via the link in the modules setting.

Share this post


Link to post
Share on other sites

The sandbox api is limited to sandbox users everywhere, so even retrieving by tag does only show images of those. You cannot get any other users media.

  • Like 1

Share this post


Link to post
Share on other sites

Hi everyone,

This is a great module. I was just wondering if anyone knows whether it would be possible for me to pull the location of each Instagram post and if so what the correct call is?

Thanks,

Matt

Share this post


Link to post
Share on other sites

@Matt_P If you use the `getRecentMedia()` endpoint you should be able to access the location inside the foreach loop.  Have a look at the instagram api, expand the response and there you'll see an example response containing all data which will be returned including a location entry.

"location": {
  "latitude": 37.778720183610183,
  "longitude": -122.3962783813477,
  "id": "520640",
  "street_address": "",
  "name": "Le Truc"
}

Code example (not tested):

<?php $feed = $modules->get('InstagramFeed')->getRecentMedia(); ?>

<div class="instagram">
  <?php foreach ($feed as $media): ?>
    // check if location is not `null`
    <?php if ($location = $media['location']): ?>
      Location: <?= $location['name'] ?>
    <?php endif; ?>
  <?php endforeach; ?>
</div>

 

  • Like 1

Share this post


Link to post
Share on other sites

Hi everyone,

Do you think it would be possible to save the last 20 or so medias (due to instagram sandbox mode), as if they would have been uploaded on the site?

In order for them not to disappear when the new posts arrive.

Mainly, the idea would be to have the complete feed displayed.

 

I did it manually with the medias urls for now but they keep changing so it's not a very suitable solution…

 

Thanks

Share this post


Link to post
Share on other sites

hi @Tanky you could add an image field to your page and save the image there.

Try something like the following:

$page->of(false);
$page->images->add($media['images']['standard_resolution']['url']);
$page->save("images");

 

Share this post


Link to post
Share on other sites

I pasted your code in the foreach that I use to generate each media of the feed:

$page->setOutputFormatting(false);
$page->insta_image->add($media['images']['standard_resolution']['url']);
$page->save("insta_image");

It returns me this error, which is weird because you already disabled the output formatting:

Error: Exception: Can't save field from page 1: /: Call $page->setOutputFormatting(false) before getting/setting values that will be modified and saved. [insta_image] (in /home/tenutaxyit/www/wire/core/PagesEditor.php line 783)

 

And there is something else I thought about, each time someone will load the page the images will be saved again, so how could I check if a media is already backed up before saving it?

Share this post


Link to post
Share on other sites

@Tanky Sorry, I have not the time at the moment to try this myself. But this is more a general topic, please try to use the forum search, I know there are a lot of topics which cover how to add an image via api. If you want to have an "archive"/Feed of all images/posts, you should consider to decouple the process of saving images from displaying it on the webpage. I would set up a cronjob or something like this which "asks" repeatedly at certain time intervals whether there are new posts. Then you could add a new Page / Page-Table-Item / Repeater-Item (it's up to you how to save it) containing the image and all the desired data (location, comments, ..) as well as the id (`$media['id'|`). Simply check if you already have an item with that id. You could also check whether `$media['created_time']` is greater than the last inserted item.

Or even better: the endpoint supports additional parameters which could be implemented as well:

MAX_ID    Return media earlier than this max_id.
MIN_ID    Return media later than this min_id.

Using MIN_ID you should be able to only receive new posts/images.

Share this post


Link to post
Share on other sites
On 18/10/2016 at 2:42 PM, Tom. said:

I keep getting the following error - [InstagramFeed]: No user '' was found. However it's working fine. 

Hi @Tom., did you solve this? It is working fine, but the the error keeps popping up.

58a88e8c5e2a8_ScreenShot2017-02-18at19_12_15.png.e7044782bfa606426a508b460d425bd8.png

I commented out line #317 of InstagramFeed.module to stop the logging for now.

58a88e54baaf3_ScreenShot2017-02-18at19_10_00.png.84587a9e5a584c006ff6608c63c6aaa8.png

 

Share this post


Link to post
Share on other sites

Here's a question. is there a way of setting the imageCount value when initialising the module. I don't think there is taking a look at the modules methods but perhaps I'm wrong?

This might be handy in the instance where you want to have one page show say 4 images and another show 8.

I know you could do this when iterating and limit but might be able to set limit based on each instance of the instagram feed?

Share this post


Link to post
Share on other sites

There you go:

<?php $feed = $modules->get('InstagramFeed')->setImageCount(8)->getRecentMedia();  ?>

 

  • Like 2

Share this post


Link to post
Share on other sites

Has any one noticed a problem with Instagram posts with multiple images not showing?

I get the output:

// output video  

suggesting that "multiple image" posts are not picked up as media type "image".

<?php if ($media['type'] === 'image'): ?>

With thanks...

Share this post


Link to post
Share on other sites

Found a fix for posts with multiple images...

Replace

// output video

with:

      <a href="<?=$media['link']; ?>" class="instagram-item">
        <picture>
          <source media="(min-width: 55rem)" srcset="<?=$media['images']['standard_resolution']['url']; ?>">
          <source media="(min-width: 45rem)" srcset="<?=$media['images']['low_resolution']['url']; ?>">
          <source srcset="<?=$media['images']['thumbnail']['url']; ?>">
          <img src="<?=$media['images']['thumbnail']['url']; ?>" alt="">
        </picture>
      </a>

e.g.

<div class="instagram">
  <?php foreach ($feed as $media): ?>
    <?php if ($media['type'] === 'image'): ?>
      <a href="<?=$media['link']; ?>" class="instagram-item">
        <picture>
          <source media="(min-width: 55rem)" srcset="<?=$media['images']['standard_resolution']['url']; ?>">
          <source media="(min-width: 45rem)" srcset="<?=$media['images']['low_resolution']['url']; ?>">
          <source srcset="<?=$media['images']['thumbnail']['url']; ?>">
          <img src="<?=$media['images']['thumbnail']['url']; ?>" alt="">
        </picture>
      </a>
    <?php else: ?>
      <a href="<?=$media['link']; ?>" class="instagram-item">
        <picture>
          <source media="(min-width: 55rem)" srcset="<?=$media['images']['standard_resolution']['url']; ?>">
          <source media="(min-width: 45rem)" srcset="<?=$media['images']['low_resolution']['url']; ?>">
          <source srcset="<?=$media['images']['thumbnail']['url']; ?>">
          <img src="<?=$media['images']['thumbnail']['url']; ?>" alt="">
        </picture>
      </a>
    <?php endif; ?>
  <?php endforeach; ?>
</div>

 

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By BitPoet
      Since I was stuck to my flat today I took up a wish and rolled a Process module / CKEditor plugin combo that adds @-autocomplete like the mentions here in the forum to CKEditor fields. It's configurable, but only in module settings for now, the positioning of the select list is quite off and there's still some visual work to be done, so it is in early alpha state.
      Nonetheless, if you want to take a look, here it is:
      https://github.com/BitPoet/ProcessMention

       
      After installation, you may want to look into the "Additional selector" entry in the module's settings. You will most likely want to limit results to certain templates there.
       
      Edit: Updated to version 0.0.30 with fixed positioning of the dropdown.
      Edit2: Settings are configurable in field context now. If pwmentions is enabled, the according settings are shown on the "Input" tab.
       
    • By thuijzer
      https://github.com/thuijzer/processwire-FieldtypeBusinessHours
      Fieldtype Business Hours
      ProcessWire Fieldtype for entering business hours (opening hours)
       
      Input format
      Leave a day empty when closed on that day
      Times are in 24 hour format.
      9:00-12:00 9:00-12:00, 13:00-17:30 16:00-2:00  
      Usage in templates
      Days are from 1 to 7 where 1 is Monday and 7 is Sunday (ISO-8601)
      echo $page->field_name->isNowOpen() ? 'Now open' : 'Now closed'; if($page->field_name[1] == null) { echo 'Closed on Monday'; } if($page->field_name[2]->inRange('11:00')) { echo 'Tuesday at 11:00 open'; } echo $page->field_name[1]; echo $page->field_name[1]->getEntries()->getFrom()->format('H:i');  
    • By hellomoto
      I was working on this:
      class PWCRM extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Client Relationship Management', 'version' => .001, 'singular' => true, 'autoload' => true ); } public function init() {} public function ready() { $this->pages->addHookBefore('render', $this, 'accessHook'); $this->pages->addHookAfter('render', $this, 'hookAfterPageRender'); } public function accessHook(HookEvent $event) { $page = $this->wire('page'); if (!strpos($page->template->tags, 'crm')) return; if (!$this->wire('user')->hasRole('crm')) $this->wire('session')->redirect($this->wire('config')->urls->login);//throw new Wire404Exception(); } public function hookAfterPageRender(HookEvent $event) { $page = $event->object; echo $page->template->tags; if (!strpos($page->template->tags, 'crm')) return; echo $this->wire('config')->urls->templates; include_once($this->wire('config')->urls->templates.'functions.inc'); $pagehtml = $event->return; $pagehtml = str_replace( '</head>', '<link id="css_crm" rel="stylesheet" href="'.$this->wire('config')->urls->templates.'css/crm.css"> </head>', $pagehtml ); $event->return = $pagehtml; //$event->replace = true; } } I have tried placing the hooks into the init() function, and more... Neither method is effective. The echoes now output, but no redirection (although I have the access settings for the top-level template for this set to render a 404 for underprivileged users, which it does, overriding this, but nonetheless this should work aside from that.
      Then I wrote this up quick:
      <?php namespace ProcessWire; class MaintenanceMode extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Maintenance Mode', 'version' => 1, 'summary' => 'Disables the website frontend for non-superusers.', 'singular' => true, 'autoload' => true, 'permanent' => false ); } public function init() { $this->addHookBefore('Page::render', $this, 'displayDecide'); } public function displayDecide($event) { $page = $event->object; if ($page->template == 'admin' || $this->wire('user')->hasRole('superuser')) return; // replace the method hooked $event->replace = true; $event->return = "Patience please while we undergo some brief maintenance work."; } } which likewise avails nothing. What the hell is my problem here? 
    • By adrian
           Tracy Debugger for ProcessWire
      The ultimate “swiss army knife” debugging and development tool for the ProcessWire CMF/CMS
       

       
      Integrates and extends Nette's Tracy debugging tool and adds 30+ custom tools designed for effective ProcessWire debugging and lightning fast development
      The most comprehensive set of instructions and examples is available at: https://adrianbj.github.io/TracyDebugger
      Modules Directory: http://modules.processwire.com/modules/tracy-debugger/
      Github: https://github.com/adrianbj/TracyDebugger
      A big thanks to @tpr for introducing me to Tracy and for the idea for this module and for significant feedback, testing, and feature suggestions.