【问题标题】:Handling user authorization with Instagram API使用 Instagram API 处理用户授权
【发布时间】:2014-11-24 20:43:33
【问题描述】:

我正在构建一个非常简单的 Web 应用程序。在用户使用 Instagram 登录后,我无法处理代码返回。我还在使用另一个 API 来帮助我,你可以在这里找到它:https://github.com/cosenary/Instagram-PHP-API

我的主页登录用户可以看到下面的php代码

<?php

require 'Instagram.php';
use MetzWeb\Instagram\Instagram;

// initialize class
     $instagram = new Instagram(array(
     'apiKey'      => 'YOUR_APP_KEY',
     'apiSecret'   => 'YOUR_APP_SECRET',
     'apiCallback' => 'YOUR_APP_CALLBACK' // must point to success.php
     ));

// create login URL
 $loginUrl = $instagram->getLoginUrl();

?>

用户已成功发送到 Instagram 登录页面,但是当他们授权我的应用时,Instagram 以 http://your-redirect-uri?code=CODE 响应时,下一页无法呈现。

您可以看到应该在下面显示的“成功”页面的代码。

/**
* Instagram PHP API
*
* @link https://github.com/cosenary/Instagram-PHP-API
* @author Christian Metz
* @since 01.10.2013
*/

require_once 'Instagram.php';
use MetzWeb\Instagram\Instagram;

// initialize class
$instagram = new Instagram(array(
'apiKey'      => 'YOUR_APP_KEY',
'apiSecret'   => 'YOUR_APP_SECRET',
'apiCallback' => 'YOUR_APP_CALLBACK' // must point to success.php
));

// receive OAuth code parameter
$code = $_GET['code'];

// check whether the user has granted access
if (isset($code)) {

// receive OAuth token object
$data = $instagram->getOAuthToken($code);
$username = $username = $data->user->username;

// store user access token
$instagram->setAccessToken($data);

// now you have access to all authenticated user methods
$result = $instagram->getUserMedia();

} else {

// check whether an error occurred
if (isset($_GET['error'])) {
echo 'An error occurred: ' . $_GET['error_description'];
}

}

?>

如果用户取消授权请求,“成功”页面会正确呈现并显示正确的错误消息。所以我相信我的问题在于 Instagram 返回到我的网络应用程序的代码参数的处理。谢谢您的帮助。

【问题讨论】:

    标签: php instagram instagram-api


    【解决方案1】:

    检查YOUR_APP_CALLBACK 重定向网址是否正确 - 此处应与您的 Instagram 应用中的相同。在此处查看他们可接受的重定向网址指南:http://instagram.com/developer/authentication/

    只要设置了$_GET['code'];,那么插件应该会处理其余的事情,所以我会检查它是否也被设置了。

    如果您还没有这样做,请查看插件示例here。 那应该让你开始。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-02
      • 2020-02-18
      • 2019-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-28
      • 1970-01-01
      相关资源
      最近更新 更多