We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28814 ☆ A M B ☆
    • 1,086 Posts
    Hi guys,

    Not sure if it's actual for anybody but here it is: snippet "Instagram Latest Posts".

    This snippet allows us to get the latest posts from any Instagram user. Access tokens are not required.

    N.B.! Please take into account, 20 latest posts can be returned only as it's limited by Instagram.

    UPDATE: Please use Github https://github.com/igorsuhinin/modx-instagram-latest-posts to get the updated code. [ed. note: suhinin last edited this post 9 years, 9 months ago.]
      Разработка сайтов и программных модулей на MODX.
      Опыт работы на MODx с 2005 года. Высокое качество.
      Компания Baltic Design Colors: http://www.bdcolors.ru.
      • 3749
      • 24,544 Posts
      Very nice. Do you mind if I do a blog post on this sometime down the road?
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 28814 ☆ A M B ☆
        • 1,086 Posts
        Hi BobRay,

        No problem, please post it anywhere you want smiley

        Hope it will be useful for somebody else.

        I'm going to make some small updates in the code. I will post it soon there and on Github as well.
          Разработка сайтов и программных модулей на MODX.
          Опыт работы на MODx с 2005 года. Высокое качество.
          Компания Baltic Design Colors: http://www.bdcolors.ru.
          • 3749
          • 24,544 Posts
          Thanks. It's a great little bit of code.

          You probably know this, but the file_get_contents() call may fail (e.g., if allow_url_fopen is off). You might consider adding a section that tries using cURL if the file_get_contents() fails.

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 28814 ☆ A M B ☆
            • 1,086 Posts
            Good point, BobRay. I will update the code to add cURL if this method is not available. Though cURL can be disabled as well smiley anyway you are the second person already who advised me to do that so it's really important thing.
              Разработка сайтов и программных модулей на MODX.
              Опыт работы на MODx с 2005 года. Высокое качество.
              Компания Baltic Design Colors: http://www.bdcolors.ru.
              • 28814 ☆ A M B ☆
              • 1,086 Posts
              Hi BobRay,

              Please check the updated code on Github https://github.com/igorsuhinin/modx-instagram-latest-posts

              I've refactored the code and added some checkings like if file_get_contents() is enabled and so on. [ed. note: suhinin last edited this post 9 years, 9 months ago.]
                Разработка сайтов и программных модулей на MODX.
                Опыт работы на MODx с 2005 года. Высокое качество.
                Компания Baltic Design Colors: http://www.bdcolors.ru.
                • 3749
                • 24,544 Posts
                Looks great!

                One minor comment: If the snippet has default properties (or a user creates them), isset() will always return true on those properties. If they're empty, the empty value will be used instead of your default.

                The usual solution is this:

                $prop = $this->modx->getOption('propName', $scriptProperties, 'default', true);


                The final argument makes it use the default value if the property is empty and the default will be used if the property is not set. Of course you need to handle things differently if 0 or an empty string is a valid value.

                MODX sets $scriptProperties for you -- an associative array with all the properties and their values.

                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 28814 ☆ A M B ☆
                  • 1,086 Posts
                  BobRay, thank you for your useful comments.

                  I've updated the code here https://github.com/igorsuhinin/modx-instagram-latest-posts/blob/master/snippet.php

                  Could you please take a look at this if all is good now?
                    Разработка сайтов и программных модулей на MODX.
                    Опыт работы на MODx с 2005 года. Высокое качество.
                    Компания Baltic Design Colors: http://www.bdcolors.ru.
                    • 3749
                    • 24,544 Posts
                    It looks perfect.

                    Maybe you could release it as an extra?
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 28814 ☆ A M B ☆
                      • 1,086 Posts
                      I would love to do that but unfortunately I have no experience with it yet smiley Though maybe it's time to learn how it works.
                        Разработка сайтов и программных модулей на MODX.
                        Опыт работы на MODx с 2005 года. Высокое качество.
                        Компания Baltic Design Colors: http://www.bdcolors.ru.