如何使用Instagram API来var_dump用户数据?

时间:2016-06-27 19:10:05

标签: php instagram access-token instagram-api

我在这里找到了这个很棒的资源:https://github.com/galen/PHP-Instagram-API

尝试使用它从Instagram中提取一些数据并转储数据,但我一直遇到问题:

(for {
  x <- ListT(xs)
  y <- ListT(ys)
  z <- ListT(none[List[Int]])
} yield x * y).run

res0: Option[List[Int]] = None

我想在我到达最后一页时没有提到客户端密码或者没有读取访问令牌。

这是我的布局,我的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(); ?> 时,它会重定向我登录Instagram。当我登录时,需要一秒钟,然后从上面找到错误页面/消息^。

我认为我的igTest.php文件错误,但我不明白我在那里错过了什么/什么让它正常工作。

1 个答案:

答案 0 :(得分:0)

  

检查出来 -

$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);
}