显示Instagram发布的json结果

时间:2017-05-11 12:54:14

标签: php jquery json ajax

我试图从Instagram api提供访问令牌,我在laravel中用ajax发送我的数据,并在json中提供access_token。 我的观点显示ajax jquery是:

  var $data;
    $(document).ready(function(){
        $("button").click(function(){
            $.ajax({

                method: 'POST',
                url:'https://api.instagram.com/oauth/access_token',
                headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                data: {client_id: "d52c34",client_secret:"<MY client_secret HERE>",
                    grant_type:"authorization_code", redirect_uri:"http://ie-asemi.ir/laravel/public/instagram/test",
                    dataType:"json",
                    processData: true,
                    code:"{{$code}}"},
                dataType:"json",
                contentType: 'application/x-www-form-urlencoded'

        });
    });


</script>

如何在此页面中获取json结果?enter image description here

我添加了更改的任务功能,enter image description here

1 个答案:

答案 0 :(得分:0)

您需要使用ajax的done方法来获取响应

var $data;
$(document).ready(function(){
     $("button").click(function(){
         $.ajax({
            method: 'POST',
            url:'https://api.instagram.com/oauth/access_token',
            headers: {'Content-Type': 'application/x-www-form-urlencoded'},
            data: {client_id: "d52c34",client_secret:"a84124d81947347fd35e9aef8",
            grant_type:"authorization_code", redirect_uri:"http://ie-asemi.ir/laravel/public/instagram/test",
            dataType:"json",
            processData: true,
            code:"{{$code}}"},
            dataType:"json",
            contentType: 'application/x-www-form-urlencoded'
      }).done(function(response) {
            console.log(response)
      });
});
</script>