2016-06-27 18 views
2

我發現這個巨大的資源在這裏:https://github.com/galen/PHP-Instagram-API如何使用Instagram API來var_dump用戶數據?

試圖用它來從Instagram的拉一些數據和轉儲出來的數據,但我一直運行到一個問題:

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 

我想客戶端機密沒有被提及或訪問令牌沒有被讀取,當我到我的最後一頁。

這是我的佈局,我igTest.php文件:

<?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(); 

?> 

,然後重定向到我igAnalytics.php文件

<?php 

    require_once('_autoloader.php'); 

    $instagram = new Instagram\Instagram($_SESSION['instagram_access_token']); 
    $current_user = $instagram->getCurrentUser(); 

    var_dump($current_user); 

?> 

_autoloader.php

<?php 

    require('_SplClassLoader.php'); 

    $loader = new SplClassLoader('Instagram', '../'); 
    $loader->register(); 

?> 

只是爲了澄清這是怎麼回事,當我去igTest.php,它重定向我登錄到Instagram。當我登錄時,需要一秒鐘的時間,並讓我看到上面的^錯誤頁面/消息。

我相信我的igAnalytics.php文件是錯誤的,但我不明白如何/什麼我缺少那裏使其正常工作。

+0

只是考慮:是你的'_autoloader.php'運行'在session_start();'? – FirstOne

+0

@FirstOne我會修改我的問題。 –

回答

0

入住這OUT-

$instagram = new Instagram([ 
     'apiKey' => 'xxxxxxxxxxxxxxxxx', 
     'apiSecret' => 'xxxxxxxxxxxxx', 
     'apiCallback' => 'CALLBACK URL' 
    ]); 
if (isset($_GET ['code']) && $_GET ['code'] != "") { 
    $code = $_GET ['code']; 
    $data = $instagram->getOAuthToken($code); 
    $user = $data->user; 
    var_dump($user); 
} else { 
    $loginUrl = $instagram->getLoginUrl(); 
    header('Location: '.$loginUrl); 
}