Making Kirbygram work with the Instagram API changes

Help!

It seems the ‘Kirbygram Dev API’ stopped working: trying to setup kirbygram by visiting the API page (and entering correct Instagram user credentials) produces the following JSON:

{"code": 403, "error_type": "OAuthForbiddenException", "error_message": "You are not a sandbox user of this client"}

But even worse: all my existing Kirbygram installations have simply STOPPED WORKING! Where the instagram posts used to show, now I see this on the page:

Notice: Undefined property: stdClass::$pagination in /[...]/site/plugins/kirbygram/lib/Instagram/Query.php on line 74

Notice: Undefined property: stdClass::$data in /[...]/site/plugins/kirbygram/lib/Instagram/Query.php on line 43

Can anyone help?.. :cold_sweat:

This is from the Kirbygram Github page:

Kirbygram is now deprecated. With Instagrams June 1st API updates the application cannot be approved under the terms and conditions so will no longer function. I’m extremely sorry for any incovenience but there is no recourse for me to have the application re-instated.

It seems I’m going to have to update all of my clients’ sites…

Is there an easy solution anywhere, or has Instagram made it impossible for everybody?..

Found this quick fix, but when you grab a new token here: http://instagram.pixelunion.net/ and then update the token in /site/plugins/kirbygram/config.json with the one you got from pixelunion your problem is solved, for now.

@vanjim It doesn’t seem to be solving it for me… I’ve pasted the new token from pixelunion, but am still getting the same error (no change). Does Kirbygram do any caching? Do we have to clear a cache?

Have now tried deleting the kirbygram/cache folder, emptying the browser cache, and re-accessing the page, but still getting the same error.

If anyone has managed to get this to work, please let us know what steps you took…

What’s strange is that the line numbers in the PHP error messages (“Undefined property: stdClass”) don’t exist/contain code in the Kirbygram code. Are you using the latest version of the plugin?

@lukasbestle Unfortunately, yes - it’s the latest version: I downloaded it directly from the GitHub repo…

Could you please post the lines from the error messages from your file?

@lukasbestle I’ll post the lines from the file here, as you requested, but the problem that the plugin is having is not likely to be something to do with the code. It certainly has to do with Instagram’s policy change, which took effect just now, on 1st June. This is not an isolated incident: every instal of Kirbygram - including the ones that have been in production successfully for several months - have suddenly thrown the same error. If you have any sites using Kirbygram, I suggest you check them right now…

Kirbygram was not the only one affected. There are several libraries, frameworks and plugins for other CMSs that have also run into strife. An old and very popular Instagram javascript library, called instafeed.js is currently broken, too - even their webpage is missing its instagram gallery. Their GitHub repo has some interesting discussions, that have been going on since November last year, when Instagram first announced these changes.

In any case, here are the lines you requested. I know you’re a miracle worker, so here’s hoping that you’ll be able to weave your magic! ;):

The error that I get is:

Notice: Trying to get property of non-object in 
/[...]/site/plugins/kirbygram/lib/Instagram/Query.php on line 74

Notice: Trying to get property of non-object in 
/[...]/site/plugins/kirbygram/lib/Instagram/Query.php on line 43

Line 74 of kirbygram/lib/Instagram/Query.php is:

$this->pagination = json_decode($content)->pagination;

In context:

public function parsePagination()
  {
	$content = $this->response->content;
	$this->pagination = json_decode($content)->pagination;
  }

Line 43 of the same file is:

return $this->content->data;

In context:

public function get()
  {
	$this->response = $this->igInstance->check_cache($this->name);

	if(!$this->response){
		$this->response = \Instagram\Remote::get($this->apiUrl . $this->endPoint, array(
			'data' => array(
				'access_token' => $this->igInstance->get_config('token'),
				'count' => 20
			)
		));
	}

	$this->content = json_decode($this->response->content);

	//echo '<pre>' . json_encode($this->response->content, JSON_PRETTY_PRINT) . '</pre>';
		
	$this->igInstance->set_cache($this->name, $this->response);
		
	$this->parsePagination();
	return $this->content->data;
  }

Thanks for the code snippets. I was wondering if this was maybe also related to Kirby 2.3, but the code is all about getting data from the response object. But since it only contains an error message now, it’s only natural that these errors are thrown here (could have been avoided with better error handling though). So you are correct that this is only related to the API change.

The authorisation tokens that were generated by Kirbygram have basically “expired” - that is, Instagram has de-authorised those tokens. In order to access the Instagram API, we need new tokens. As @vanjim pointed out above, there are a couple of companies - like Pixel Union - who are currently being able to generate accepted authorisation tokens. These tokens are exactly the same as the tokens used by Kirbygram.

So, in theory, I should be able to get a new token from Pixel Union, put that token into Kirbygram, and have it function - I think. Kirbygram is merely sending the token and user_id, and getting the JSON object from the API. Whether the token was generated by Kirbygram itself, it should not matter.

However, when I put the token in the Kirbygram config, it still doesn’t work…

I’m pretty certain that there is some sort of caching going on somewhere, which is stopping the new authorisation token from working, but I don’t know whether this caching is being done by Kirby, Kirbygram, or what.

I really need to find a way to make this work.

Ok, I got it to work. If you have an existing Kirbygram installation, here’s what you have to do:

  1. Make sure you log out of all Instagram accounts - if you are logged on with your own account or someone else’s, you will have problems.
  2. Go to http://instagram.pixelunion.net/, click on the big button and login with the credentials for the Instagram account you wish to access. Pixel Union will generate a new authorisation token for you. Copy the token.
  3. Open the kirbygram/config.json file, and change (paste) the value of the ‘token’ to the value you just copied.
  4. Now copy the first 10 characters of the token - they are the characters before the “.” (full stop). This is the User ID: paste it into ‘uid’. Save the config.json file.
  5. Last of all, empty the Kirbygram cache: delete the kirbygram/cache folder, and empty your browser’s cache.

It worked for me - at least for the time being.

This is obviously a patch-up solution. If Kirbygram’s developer has really decided to abandon it, we desperately need a new Instagram solution for Kirby…

3 Likes

i created a new plugin that works with the current instagram api.