0

我正在构建一个非常简单的 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 返回到我的网络应用程序的代码参数的处理。谢谢您的帮助。

4

1 回答 1

0

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

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

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

于 2015-02-05T15:31:14.190 回答