在laravel 5.4中为用户提供媒体

时间:2017-05-25 19:01:03

标签: php laravel instagram-api

我尝试使用Access_token来提供用户媒体。 我以这种方式给Code和Access_token: 我的控制器和视图有此代码:

    public function indexx(Request $request)
{
    $code = $this->code = $request->get('code');


    try {
        $client = new Client();
        $res = $client->request('POST', 'https://api.instagram.com/oauth/access_token', [
            'form_params' => [
                'client_id' => ''client_id',
                'client_secret' => 'client_secret' ,
                'grant_type' => 'authorization_code',
                'redirect_uri'=> 'http://asemi.ir/laravel/public/instagram/s,                     'code' => $code
            ]
        ]);
        $status = $res->getStatusCode();
        if ($status == 200) {
            $body = $res->getBody();
            $obj = \GuzzleHttp\json_decode($body);

            //(cookie('access', $access, 45000));
            $username = $obj->user->username;
            $img = $obj->user->profile_picture;
            $full_name = $obj->user->full_name;
            $bio = $obj->user->bio;
            $website = $obj->user->website;
             $access_token=$obj->access_token;
            $data = array(
                'username' => $username,
                'img' => $img,
                'full_name' => $full_name,
                'bio' => $bio,
                'website' => $website,
                 'access' => $access_token
            );

          echo view('json')->with($data);

        } else {
            echo "status is not 200";
        }

    } catch (BadResponseException $e) {
        echo "error1";
    }

并且视图文件包含以下代码:

<script>
    $(document).ready(function () {
        $("button").click(function () {
            $.ajax({
                method: 'GET',
                url: './amir?code={{$code}}',
                success: function (data) {
                    $("#test").html(data);
                }
            });
        });
    });

如何在控制器中使用access_token与json和Guzzle为用户提供媒体?

0 个答案:

没有答案