justb3a

Module: Instagram Feed

Recommended Posts

— Is there a way to update the cache every 60 seconds?

Nope. This module uses the built-in WireCache functionality which defines the following caching periods:

const expireNow = 0;
const expireHourly = 3600; 
const expireDaily = 86400;
const expireWeekly = 604800;
const expireMonthly = 2419200;

— Is it possible to access the "high_resolution" endpoints, even though they aren't already implemented in instagram API (files are there but not implemented)?

This isn't possible, this module just uses the existing instagram endpoints.

  • Like 2

Share this post


Link to post
Share on other sites

Hi, I did just a short look at the instagram api and both implemented endpoints seem to submit a media-id inside the returned array. If this is not the right one, if have no idea as well

{
    "data": [{
        "comments": {
            "count": 0
        },
        ...
        "type": "image",
        "id": "22721881",
        ...
    }]
}

Share this post


Link to post
Share on other sites

My app is kind of a social wall that is running for days/weeks on end and I would like to automate the retrieval of a new access token.
 
Problem: we never know when Instagram might decide to revoke the access token.
 
Once the old one has been revoked, the Instagram API will return error_type=OAuthAccessTokenError. Whenever the response contains this, I would like to generate a new one automatically and save it to the module settings.
 
Looking at the getCode() method, it requires superuser priviliges to get the access token because the redirect URL for getting the code from Instagram lies within the PW admin.
 
So I tink I need to provide a publicly accessible redirect URL to handle the process of aquiring the new access token. Am I heading in the right direction here?
 
(Sorry if this may sound like a silly question. But it is the first time for me working with the Instagram API).
 
EDIT: Sorry, I should have read through the module code more carefully. I think, all it takes to automate retrieval of new access token is modifications to
1. sendRequest method to handle authorization failure and get the new accesstoken
2. getCode method to allow handing back the URL for code retrieval when not logged in as superuser
3. have a module setting to cater for automatic update of access token
 
I will give it a shot and report back here how it goes.
 
2nd EDIT: After doing quite some digging and reading carefully through the Instagram API docs and usage policy, I found that the API is not supposed to be used for automated aquisition of access tokens the way I was originally planning it and the way I can do it eg with Twitter API. Instagram is pretty restrictive  and they clearly state in their Platform Policy

Do not abuse the API Platform, automate requests, or encourage unauthentic behavior. This will get your access turned off.

Various sources state that their access token has been working for quite a long time (up to 3 years). So I don't worry too much about the access token being revoked during the time my social wall will be up.

Anyways, I will cater for the rare case that the access token is invalid at some point in time. I will extend this great module so that the superuser gets notified by email when authentication problems occur during requests to the API. Then they can do a manual refresh of the access token through the link in the module admin interface.

Share this post


Link to post
Share on other sites

To retrieve tagged media with

$media =  $modules->get('InstagramFeed)->getRecentMediaByTag('mytag')

  I had to add scope=public_content to the url for getting the code in the getCode() method:

      $request = array(
        'client_id' => $this->clientId,
        'redirect_uri' => $redirect,
        'response_type' => 'code',
        'scope' => 'public_content'
      );

After that I had to click the 'get Access Token' link again and renew the permissions for the app.

Otherwise I always received an empty result.

In the Instagram API docs they state that the public_content scope is required.

With the module as is now, it only gets the basic permissions in the getCode() method by omitting the scope parameter. (more about scopes in the API docs)

Can anyone confirm that they have successfully received results for the getRecentMediaByTag() call without adding scope=public_content to the 'get Access Token' link url?

Share this post


Link to post
Share on other sites

Hello, 

seems to be the right one. 

Hi, I did just a short look at the instagram api and both implemented endpoints seem to submit a media-id inside the returned array. If this is not the right one, if have no idea as well

{
    "data": [{
        "comments": {
            "count": 0
        },
        ...
        "type": "image",
        "id": "22721881",
        ...
    }]
}

But how to make a call now ? From the Module ? 

I treid do realize it self but my php are not enough for this currently. 

Share this post


Link to post
Share on other sites

@iNoize

To make a call, you need to have the module installed and gone through the process of generating your access token (which is desribed in the module howto).

Then you can make calls from anywhere in yoru templates:

$instagram = $modules->get('InstagramFeed'); // load the module

$userMedia = $instagram->getRecentMedia(); // get media of your user

Then you should have a look at the PHP example to see how you can access values inside $userMedia.

$userMedia is just an example name. You can call that whatever you want. in the PHP example it is called $feed. $feed is an array of the media for that instagram user. You need to loop through that array in a foreach to access the contained media items and extract their properties for display.

Share this post


Link to post
Share on other sites

@gebeer thanks for your advice it works for me like in the examples but what i need is the  last comments self, 

if put out the whole feed 

<pre>
<?php vardump($feed); ?>
</pre>

there are no comments in the array ? So my question was is it possible with this module ? or is it possible to rewrite a litle this module ? 

my php skills are not so good that i could do it self. 

Share this post


Link to post
Share on other sites

@iNoize

getting comments is not implemented in the module. One would have to extend the module code to call the comments endpoint for every media object.

Sorry, but I don't have the time for this right now.

Share this post


Link to post
Share on other sites

@iNoize

getting comments is not implemented in the module. One would have to extend the module code to call the comments endpoint for every media object.

Sorry, but I don't have the time for this right now.

Thanks for testing. Using this endpoint you just get the number of comments, not the comment itself.

["comments"]=>
  array(1) {
    ["count"]=>
    int(1)
}

Share this post


Link to post
Share on other sites

Here you go: new InstagramFeed version 1.0.0  :)

  • add required scope public_content to retrieve tagged media with getRecentMediaByTag('tag') (thanks @gebeer)
  • add ProcessWire 3.x compatibility
  • add endpoint to get a list of recent comments on a media object: getRecentComments($media)

Example:

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

<div class="instagram>
  <?php foreach ($feed as $media): ?>
    <?php if ($media['type'] === 'image'): ?>
      <a href="<?=$media['link']; ?>" class="instagram-item">
        <img src="<?=$media['images']['thumbnail']['url']; ?>" alt="">
      </a>

      // display comments
      <?php $comments = $modules->get('InstagramFeed')->getRecentComments($media); ?>
      <?php if ($comments): ?>
        <ul>
          <?php foreach ($comments as $comment): ?>
            <li><?=$comment['text']?></li>
          <?php endforeach; ?>
        </ul>
      <?php endif; ?>
    <?php endif; ?>

  <?php endforeach; ?>
</div>

A comment ($comment in the example above) contains the following data:

"created_time": "1280780324",
"text": "Really amazing photo!",
"from": {
  "username": "snoopdogg",
  "profile_picture": "http://images.instagram.com/profiles/profile_16_75sq_1305612434.jpg",
  "id": "1574083",
  "full_name": "Snoop Dogg"
},
"id": "420"
  • Like 7

Share this post


Link to post
Share on other sites

@justb3a Thanks a lot but something goes wrong there in your example ? 

Share this post


Link to post
Share on other sites

@justb3a Thanks a lot but something goes wrong there in your example ? 

Ah, thanks for your hint. There was a missing opening `<?php` tag. I corrected the example above as well as the Github readme.

Share this post


Link to post
Share on other sites
On 15.6.2016 at 11:24 AM, justb3a said:

Ah, thanks for your hint. There was a missing opening `<?php` tag. I corrected the example above as well as the Github readme.

Hello, i get alway NULL or Array(0) dont really work ? 

have you tried your code ? maybe is something wrong in the access token  ? 

 

Share this post


Link to post
Share on other sites

Did you read this one https://www.instagram.com/developer/? Since 1. of June one can only access the latest 20 images of up to 5 sandbox users without going through a app review by Instagram's staff. Hashtags will also only show media of those users in sandbox mode.

Share this post


Link to post
Share on other sites

Working with iNoize, i found a way to fix this problem -> instagram.pixelunion.net/

Share this post


Link to post
Share on other sites
17 hours ago, iNoize said:

have you tried your code ?

No. Never. Should I? From time to time I dream about some code someone might need and put it inside a module :D:D :) 

 

Thanks @LostKobrakai for pointing out the sandbox mode. more about sandbox mode

 

  • Like 2

Share this post


Link to post
Share on other sites

I'm getting the following warning when trying to render the feed:

Warning: constant(): Couldn't find constant WireCache::expireWeekly in/path/to/public_html/site/assets/cache/FileCompiler/site/modules/InstagramFeed/InstagramFeed.module on line 286

I am running PW version 3.0.33.

Any thoughts what might be causing this?

Thanks for the help!

Share this post


Link to post
Share on other sites

Hm... I still seem to be having issues.

I'm getting: Warning: Invalid argument supplied for foreach()

When trying to loop the instagram posts. I'm trying to get posts by method getRecentMediaByTag

Any thoughts?

Share this post


Link to post
Share on other sites

Could you please output the variable before starting the foreach loop (var_dump($feed);). I guess it's empty. Are you sure that the generation of the access token has gone right?

Share this post


Link to post
Share on other sites

I get NULL when I do a var_dump.

I have a Client ID and Secret, then saved the page. Then came back and then clicked get access token and re-saved.

I've just tried clearing the access token, regenerating the Client secret saving the page and then getting the access token again but I'm still getting NULL.

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 OLSA
      Hello for all,
      ConfigurationForm fieldtype module is one my experiment from 2016.
      Main target to build this module was to store multiple setup and configuration values in just 1 field and avoid to use 1 db table to store just single "number of items on page", or another db table to store "layout type" etc. Thanks to JSON formatted storage this module can help you to reduce number of PW native fields in project, save DB space, and reduce number of queries at front-end.
      Install and setup:
      Download (at the bottom ), unzip and install like any other PW module (site/modules/...). Create some filed using this type of field (ConfigurationForm Fieldtype) Go to field setup Input tab and drag some subfields to container area (demo). Set "Name" and other params for subfields Save and place field to templates ("Action tab") How to use it:
      In my case, I use it to store setup and configurations values, but also for contact details, small content blocks... (eg. "widgets").
      Basic usage example:
      ConfigForm fieldtype "setup" has subfields:
      "limit", type select, option values: 5, 10, 15, 20
      "sort", type select, option values: "-date", "date",  "-sort", "sort"
      // get page children (items) $limit = isset($page->setup->limit) ? $page->setup->limit : 10; $sort = isset($page->setup->sort) ? $page->setup->sort : '-sort'; $items = $page->children("limit=$limit, sort=$sort");  
      Screenshots:


       
      Notes:
      Provide option to search inside subfields Provide multilanguage inputs for text and textarea field types Provide option for different field layout per-template basis Do not place/use field type "Button" or "File input" because it won't works. Please read README file for more details and examples Module use JSON format to store values. Text and textarea field types are multilanguage compatible, but please note that main target for this module was to store setup values and small content blocks and save DB space. Search part inside JSON is still a relatively new in MySQL (>=5.77) and that's on you how and for what to use this module.
      Thanks:
      Initial point for this fieldtype was jQuery plugin FormBuiled and thanks to Kevin Chappel for this plugin.
      In field type "link" I use javascript part from @marcostoll module and thanks to him for that part.
      Download:
      FieldtypeConfigForm.zip
      Edit: 14. August 2018. please delete/uninstall previously downloaded zip
      Regards.
         
    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public.
      Description from PW Weekly:
       
      Modules Directory: https://modules.processwire.com/modules/rock-pdf/
      Download & Docs: https://gitlab.com/baumrock/RockPdf
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread:
       
    • By bernhard
      WHY?
      This module was built to fill the gap between simple $pages->find() operations and complex SQL queries.
      The problem with $pages->find() is that it loads all pages into memory and that can be a problem when querying multiple thousands of pages. Even $pages->findMany() loads all pages into memory and therefore is a lot slower than regular SQL.
      The problem with SQL on the other hand is, that the queries are quite complex to build. All fields are separate tables, some repeatable fields use multiple rows for their content that belong to only one single page, you always need to check for the page status (which is not necessary on regular find() operations and therefore nobody is used to that).
      In short: It is far too much work to efficiently and easily get an array of data based on PW pages and fields and I need that a lot for my RockGrid module to build all kinds of tabular data.

      Basic Usage

       
      Docs & Download
      https://modules.processwire.com/modules/rock-finder/
      https://gitlab.com/baumrock/RockFinder/tree/master
       
      Changelog
      180810, v1.0.5, basic support for options fields 180528, v1.0.4, add custom select statement option 180516, change sql query method, bump version to 1.0.0 180515, multilang bugfix 180513, beta release <180513, preview/discussion took place here: https://processwire.com/talk/topic/18983-rocksqlfinder-highly-efficient-and-flexible-sql-finder-module/
    • By Thomas Diroll
      Hi guys I'm relatively new to PW and just finished developing a page for a client. I was able to include all necessary functionality using the core fieldtypes but now I it seems that I need to extend them with a custom one. What I need is a simple button, that copies the absolute url (frontend not PW-backend) of the page which is currently edited to the clipboard. As this feature is only needed inside a specific template, I tend to use a custom fieldtype which provides this feature. I've been looking inside the core modules code (eg. FieldtypeCheckbox.module) but I don't really get the structure of it and how its rendered to the admin page. I also didn't find a lot of tutorials covering custom fieldtypes.
      Maybe some of you could give me some tips on how to write a basic custom fieldtype that renders a button which copies the value of
      page->httpUrl() to the clipboard using JS. Thanks!
    • By bernhard
      Some of you might have followed the development of this module here: https://processwire.com/talk/topic/15524-previewdiscussion-rockdatatables/ . It is the successor of "RockDataTables" and requires RockFinder to get the data for the grid easily and efficiently. It uses the open source part of agGrid for grid rendering.
       
      WHY?
      ProcessWire is awesome for creating all kinds of custom backend applications, but where it is not so awesome in my opinion is when it comes to listing this data. Of course we have the built in page lister and we have ListerPro, but none of that solutions is capable of properly displaying large amounts of data, for example lists of revenues, aggregations, quick and easy sorts by the user, instant filter and those kind of features. RockGrid to the rescue 😉 
       
      Features/Highlights:
      100k+ rows Instant (client side) filter, search, sort (different sort based on data type, eg "lower/greater than" for numbers, "contains" for strings) extendable via plugins (available plugins at the moment: fullscreen, csv export, reload, batch-processing of data, column sum/statistics, row selection) all the agGrid features (cell renderers, cell styling, pagination, column grouping etc) vanilla javascript, backend and frontend support (though not all plugins are working on the frontend yet and I don't plan to support it as long as I don't need it myself)  
      Limitations:
      While there is an option to retrieve data via AJAX the actual processing of the grid (displaying, filtering, sorting) is done on the client side, meaning that you can get into troubles when handling really large datasets of several thousands of rows. agGrid should be one of the most performant grid options in the world (see the official example page with a 100k row example) and does a lot to prevent problems (such as virtual row rendering), but you should always have this limitation in mind as this is a major difference to the available lister options that do not have this limitation.
      Currently it only supports AdminThemeUikit and I don't plan to support any other admin theme.
       
      Download: https://gitlab.com/baumrock/RockGrid
      Installation: https://gitlab.com/baumrock/RockGrid/wikis/Installation
      Quikckstart: https://gitlab.com/baumrock/RockGrid/wikis/quickstart
      Further instructions: https://gitlab.com/baumrock/RockGrid/wikis/quickstart#further-instructions
       
      Module status: alpha, License: MIT
      Note that every installation and uninstallation sends an anonymous google analytics event to my google analytics account. If you don't want that feel free to remove the appropriate lines of code before installation/uninstallation.
       
      Contribute:
      You can contribute to the development of this and other modules or just say thank you by
      testing, reporting issues and making PRs at gitlab liking this post buying me a drink: paypal.me/baumrock/5 liking my facebook page: facebook.com/baumrock hiring me for pw work: baumrock.com  
      Support: Please note that this module might not be as easy and plug&play as many other modules. It needs a good understanding of agGrid (and JavaScript in general) and it likely needs some looks into the code to get all the options. Please understand that I can not provide free support for every request here in the forum. I try to answer all questions that might also help others or that might improve the module but for individual requests I offer paid support for 60€ per hour.
       
      Changelog
      180730 support subdir installations 180711 bugfix (naming issue) 180630 alpha realease  
      Use Cases / Examples:
      Colored grid cells, Icons, Links etc. The Grid also has a "batcher" feature built in that helps communicating with the server via AJAX and managing resource intensive tasks in batches:

      Filters, PW panel links and instant reload on panel close:

      You can combine the grid with a chart library like I did with the (outdated) RockDataTables module: