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