I found this great resource here: https://github.com/galen/PHP-Instagram-API
Trying to use it to pull some data from Instagram and dump out the data, but I keep running into a problem:
Fatal error:
Uncaught exception 'Instagram\Core\ApiException' with message 'Missing client_id or access_token URL parameter.' in /home/user/Instagram/Core/Proxy.php:553
Stack trace:
#0 /home/user/Instagram/Core/Proxy.php(257): Instagram\Core\Proxy->apiCall('get', 'https://api.ins...')
#1 /home/user/Instagram/Instagram.php(176): Instagram\Core\Proxy->getCurrentUser()
#2 /home/user/public_html/igAnalytics.php(6): Instagram\Instagram->getCurrentUser()
#3 {main} thrown in /home/user/Instagram/Core/Proxy.php on line 553
I guess the client secret isn't being mentioned or the access token isn't being read when I get to my final page.
Here's my layout, my igTest.php
file:
<?php
require_once( '_autoloader.php' );
$auth_config = array(
'client_id' => 'myid',
'client_secret' => 'mysecret',
'redirect_uri' => 'http://example.com/igAnalytics.php',
'scope' => array( 'likes', 'comments', 'relationships' )
);
$auth = new Instagram\Auth( $auth_config );
$auth->authorize();
$_SESSION['instagram_access_token'] = $auth->getAccessToken( $_GET['code'] );
$instagram = new Instagram\Instagram;
$instagram->setAccessToken( $_SESSION['instagram_access_token'] );
$current_user = $instagram->getCurrentUser();
?>
Which then redirects to my igAnalytics.php
file
<?php
require_once( '_autoloader.php' );
$instagram = new Instagram\Instagram( $_SESSION['instagram_access_token'] );
$current_user = $instagram->getCurrentUser();
var_dump($current_user);
?>
My _autoloader.php
:
<?php
require( '_SplClassLoader.php' );
$loader = new SplClassLoader( 'Instagram', '../' );
$loader->register();
?>
Just to clarify what's going on, when I go to igTest.php
, it redirects me to login to Instagram. When I login, it takes a second and gets me to that error page/message from above ^.
I believe that my igAnalytics.php
file is wrong, but I don't understand how/what I'm missing there to make it work properly.