【问题标题】:show json result that instagram posted显示 Instagram 发布的 json 结果
【发布时间】:2017-05-11 12:54:14
【问题描述】:

我正在尝试从 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

我添加了 done 函数,一切都改变了,enter image description here

【问题讨论】:

  • 您使用.done() 来返回数据响应。如果是 JSON,则可以轻松访问。 See the examples in the docs here.
  • 复制和粘贴包含client_secret的代码时要小心
  • @samiles 我是 jquery 新手,你能帮我更多吗?
  • @ThrowingSpoon 好的,谢谢

标签: php jquery json ajax


【解决方案1】:

需要使用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>

【讨论】:

  • 我正在检查此代码,但我没有显示 json 结果
  • 您正在检查控制台,对吗?控制台打印什么......可能有什么错误?
猜你喜欢
  • 2016-04-08
  • 1970-01-01
  • 2020-12-08
  • 1970-01-01
  • 1970-01-01
  • 2020-05-28
  • 1970-01-01
  • 2018-10-31
  • 2018-07-25
相关资源
最近更新 更多