Jump to content

Module: Instagram Feed


justb3a

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
Link to comment
Share on other sites

  • 3 weeks later...

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",
        ...
    }]
}
Link to comment
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.

Link to comment
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?

Link to comment
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. 

Link to comment
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.

Link to comment
Share on other sites

  • 4 weeks later...

@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. 

Link to comment
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)
}
Link to comment
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
Link to comment
Share on other sites

  • 2 weeks later...

@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.

Link to comment
Share on other sites

  • 3 weeks later...
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  ? 

 

Link to comment
Share on other sites

  • 3 months later...

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!

Link to comment
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?

Link to comment
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.

Link to comment
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
×
×
  • Create New...