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 Lex Sanchez
      Video or Social Post Embed
      Based on the TextformatterVideoEmbed module developed by Ryan Cramer, we have added the possibility to embed publications of the main social networks Facebook, Twitter and Instagram.
      ProcessWire Textformatter module that enables translation of YouTube, Vimeo, Instagram, Facebook, Twitter or Issuu URLs to full embed codes, resulting in a viewable video or social post in textarea fields you apply it to.
      How to install
      Download or Clone from Github: https://github.com/lexsanchez/VideoOrSocialPostEmbed
      Copy the VideoOrSocialPostEmbed.module file to your /site/modules/ directory (or place it in /site/modules/VideoOrSocialPostEmbed/).
      Click check for new modules in ProcessWire Admin Modules screen. Click install for the module labeled: "Video or Social Post Embed".
      Now you will be on the module config screen. Please make note of the config options and set as you see fit.
      How to use
      Edit your body field in Setup > Fields (or whatever field(s) you will be placing videos in). On the details tab, find the Text Formatters field and select "Video or Social Post Embed". Save.
      Edit a page using the field you edited and paste in YouTube, Vimeo, Facebook, Twitter, Instagram and/or Issuu URLs each on their own paragraph.
      Example
      How it might look in your editor (like TinyMCE):
      How it works
      This module uses YouTube, Vimeo, Instagram, Facebook, Twitter and Issuu oEmbed services to generate the embed codes populated in your content. After these services are queried the first time, the embed code is cached so that it doesn't need to be pulled again.
      Configuration
      You may want to update the max width and max height settings on the module's configuration screen. You should make these consistent with what is supported by your site design.
      If you change these max width / max height settings you may also want to check the box to clear cache, so that YouTube/Vimeo/Facebook/Twitter/Instagram/Issuu oembed services will generate new embed codes for you.
      Using with Markdown, Textile or other LML
      This text formatter is looking for a YouTube, Vimeo, Instagram, Facebook, Twitter or Issuu video URL surrounded by paragraph tags. As a result, if you are using Markdown or Textile (or something else like it) you want that text formatter to run before this one. That ensures that the expected paragraph tags will be present when VideoOrSocialPostEmbed runs. You can control the order that text formatters are run in by drag/drop sorting in the field editor.
      Copyright 2018 by Ryan Cramer / Updated by Lex Sanchez
    • By kixe
      Email Verification
      This module provides functions to validate email adresses and hosts. The module generates a textfile for blacklisted mailhosts (trashmail), which will be always up to date.
      Download
      https://modules.processwire.com/modules/email-verification/
      API
      // get module $mailcheck = $modules->get('EmailVerification'); // return bool/ string - automatted update of blacklist file $mailcheck->blacklisted(email|domain) // return bool - validate a top level domain, checks against IANA list $mailcheck->validTLD(tld) // return array of punycoded TLDs - cyclic updated, data pulled from IANA $mailcheck->getTLDs(cycle=2592000) // return bool - checks syntax converts to punycode $mailcheck->validDomainName(domain); // return bool - checks punycode encoded syntax $mailcheck->validHostName(host); // return bool - checks syntax and accessibility $mailcheck->validHost(email|domain) // add a single value to blacklist $mailcheck->addToBlacklist(email|domain) USAGE
      $mailcheck = $modules->get('EmailCheck'); $email = 'susi@trashmail.com'; if($mailcheck->blacklisted($email)) echo 'Email Provider not allowed'; if(!$mailcheck->validHost($email)) echo 'Mailhost not available'; Example blacklist file:  blacklist.txt
       
    • By teppo
      Code Blocks Textformatter is a tiny Textformatter module I cooked up to add support for code blocks to text/textarea/RTE fields on some of the sites I work with. Unlike a full-blown Markdown Textformatter – which is something that we already have in the core – this module simply adds support for fenced and inline code blocks.
      The syntax is based on the GitHub code block documentation, so please refer to that for additional instructions. The README at GitHub also includes some basic examples. As with any Textformatter, in order to enable this one, install it and enable it via field settings. Note that there's no syntax highlighting built in (at least for the time being), so use a tool of your choice for that – personally I prefer Prism.js.
      Since this module doesn't use a Markdown tool behind the scenes, but rather some home baked regular expressions, there's always the possibility that I've missed something – but please let me know if you use this module and run into any issues. On the other hand this module should be relatively fast and unobtrusive, as there are no unnecessary bits of code to run 
      GitHub repository: https://github.com/teppokoivula/TextformatterCodeBlocks Modules directory: http://modules.processwire.com/modules/textformatter-code-blocks/
    • By theo
      Here is my first processwire module (beta).
      https://github.com/theo222/ImagePickerField
      A lot of "first times". First time Github, Markdown and of course PW Modules.
      So be gentle please.
      I hope it works.