I try to login by Instagram , and I refer mbarwick83/instagram.
When I try to login,it have some problem,only show some url:
https://api.instagram.com/oauth/authorize?response_type=code
And go to url,have some message:
// 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"
}
But I already setting "client_id" and "redirect_uri".
How can I fix this problem?Thanks.
Step by Step:
1.Install mbarwick83/instagram
composer require mbarwick83/instagram
providers:Mbarwick83\Instagram\InstagramServiceProvider::class
aliases:'Instagram'=> Mbarwick83\Instagram\Facades\Instagram::class
use Mbarwick83\Instagram\Instagram;
4.To publish the packages configuration file
php artisan vendor:publish
5.Add Controller
<?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.Setting "client_id" and "redirect_uri":
Path: ../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.Setting ../routes/web.php
Route::get('login/Instagram', 'Mbarwick83Controller@index');
Route::get('login/Instagram/callback', 'Mbarwick83Controller@callback');
8.Setting ../.env
INSTAGRAM_CLIENT_ID=0264df467XXXXXX
INSTAGRAM_CLIENT_SECRET=6e5d9XXXXX4eeXX1
INSTAGRAM_CALLBACK_URL=http://localhost/login/Instagram/callback
Change your config file, remove the env function
return [
'client_id' => '0264df467XXXXXX',
'client_secret' => '6e5d9XXXXX4eeXX1',
'redirect_uri' => 'http://localhost/login/Instagram/callback',
'scopes' => 'basic public_content'
];