我尝试通过Instagram登录,并提及mbarwick83/instagram。
当我尝试登录时,它有一些问题,只显示一些网址:
https://api.instagram.com/oauth/authorize?response_type=code
转到网址,有一些消息:
// 20171025142046
// https://www.instagram.com/oauth/authorize?response_type=code
{
"error_type": "OAuthException",
"code": 400,
"error_message": "You must include a valid client_id, response_type, and redirect_uri parameters"
}
但我已经设置了“client_id”和“redirect_uri”。
如何解决此问题?谢谢。
一步一步:
1.安装mbarwick83 / instagram
composer require mbarwick83/instagram
providers:Mbarwick83\Instagram\InstagramServiceProvider::class
aliases:'Instagram'=> Mbarwick83\Instagram\Facades\Instagram::class
use Mbarwick83\Instagram\Instagram;
4.发布包配置文件
php artisan vendor:publish
5.添加控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Mbarwick83\Instagram\Instagram;
use App\Http\Requests;
class Mbarwick83Controller extends Controller
{
public function index(Instagram $instagram)
{
return $instagram->getLoginUrl();
}
public function callback(Request $request, Instagram $instagram)
{
$response = $instagram->getAccessToken($request->code);
// or $response = Instagram::getAccessToken($request->code);
if (isset($response['code']) == 400)
{
throw new \Exception($response['error_message'], 400);
}
return $response['access_token'];
}
}
6.设置“client_id”和“redirect_uri”:
路径:../ vendor / mbarwick83 / instagram / src / config
<?php
return [
'client_id' => env('0264df467XXXXXX'),
'client_secret' => env('6e5d9XXXXX4eeXX1'),
'redirect_uri' => env('http://localhost/login/Instagram/callback'),
'scopes' => 'basic public_content'
];
7.设置../ routes / web.php
Route::get('login/Instagram', 'Mbarwick83Controller@index');
Route::get('login/Instagram/callback', 'Mbarwick83Controller@callback');
8.设置../。env
INSTAGRAM_CLIENT_ID=0264df467XXXXXX
INSTAGRAM_CLIENT_SECRET=6e5d9XXXXX4eeXX1
INSTAGRAM_CALLBACK_URL=http://localhost/login/Instagram/callback
答案 0 :(得分:1)
更改配置文件,删除env功能
return [
'client_id' => '0264df467XXXXXX',
'client_secret' => '6e5d9XXXXX4eeXX1',
'redirect_uri' => 'http://localhost/login/Instagram/callback',
'scopes' => 'basic public_content'
];
答案 1 :(得分:1)
您使用env()
错误,它需要一个密钥名称,而不是值。 (虽然您可以设置&#34;默认值&#34;作为第二个参数)
<?php
return [
'client_id' => env('INSTAGRAM_CLIENT_ID'),
'client_secret' => env('INSTAGRAM_CLIENT_SECRET'),
'redirect_uri' => env('INSTAGRAM_CALLBACK_URL'),
'scopes' => 'basic public_content'
];
env('INSTAGRAM_CLIENT_ID')
将从INSTAGRAM_CLIENT_ID
文件中获取.env
的值。