如何使用oriceon / oauthlaravel-5-laravel实现Instagram注册

时间:2016-01-14 11:21:40

标签: php oauth laravel-5 instagram

我用oriceon / oauth-laravel创建了 fb注册和twitter注册。我也想要Instagram。但我坚持到这里。在提供的文档中有fb和twitter的控制器方法{{ 3}}。我也想要一个适用于Instagram的控制器方法。帮助我。

1 个答案:

答案 0 :(得分:4)

就像fb,Twitter和谷歌在指定链接中所代表的那样,Instagram可以像这样应用。,

$code = $request->get('code');

        // get fb service
        $instagramService = \OAuth::consumer('Instagram');

        // check if code is valid

        // if code is provided get user data and sign in
        if ( ! is_null($code))
        {
            // retrieve the CSRF state parameter
            $state = isset($_GET['state']) ? $_GET['state'] : null;
            // This was a callback request from Instagram, get the token
            $instagramService->requestAccessToken($code, $state);
            // Send a request with it
            $result = json_decode($instagramService->request('users/self'), true);
            // Show some of the resultant data
            echo 'Your unique instagram user id is: ' . $result['data']['id'] . ' and your name is ' . $result['data']['full_name'];
        } else {
            $url = $instagramService->getAuthorizationUri();
            return redirect((string)$url);
        }