ramsey / laravel-oauth2-instagram

A Laravel 5 service provider for league/oauth2-instagram
MIT License
29 stars 9 forks source link

Undefined variable: request #2

Open mccombs opened 8 years ago

mccombs commented 8 years ago

Hi there - I'm getting an error after install using your example code.

I've setup an application in instagram, hit up the authorize url ( https://api.instagram.com/oauth/authorize/?client_id=123465&redirect_uri=http://local.myapp/&response_type=code )

and when it redirects (with a code) I get the following error: Undefined variable: request

Do you have a more comprehensive example or how to complete the oauth transaction (routes/controller etc.) ?

ramsey commented 8 years ago

Can you show an example of your code?

mccombs commented 8 years ago

I was just using the sample code provided under examples. I placed this on the welcome.blade.php but I also tried just dumping it into the route too just as a raw test. Both locations gave me an error with the $request.

Instagram redirects back to my local app correctly but I'm not able run the following.

` if (!$request->has('state') || $request->state !== $request->session()->get('instagramState')) { abort(400, 'Invalid state'); }

if (!$request->has('code')) { abort(400, 'Authorization code not available'); }

$token = Instagram::getAccessToken('authorization_code', [ 'code' => $request->code, ]);

$request->session()->put('instagramToken', $token); `

ramsey commented 8 years ago

Without seeing your full controller code, it's hard to tell what's missing. It sounds like you haven't defined the $request parameter in your controller action's method signature.

This might help...

I have a repo set up with a fully-functioning Laravel application that uses this library: https://github.com/ramsey/oauth2-phparch

Check out the HomeController here: https://github.com/ramsey/oauth2-phparch/blob/master/app/Http/Controllers/HomeController.php

In an upcoming issue of php[architect] magazine, I have an article that will be covering this library and that repo is the companion source for the article. The readme should help get you going, but let me know if you have any questions.