阿贾克斯的Oauth 2.0访问令牌 [英] Ajax Oauth 2.0 access token

查看:149
本文介绍了阿贾克斯的Oauth 2.0访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着去创建一个JSON请求和我有下面的脚本,由于某种原因,我没有得到回应。任何人都可以帮助呢?

我哈弗我的道理,但我不知道在哪里,我需要把它?

 <脚本>
    $阿贾克斯(
        'https://data.brightcove.com/analytics-api/videocloud/accounts/867903724001/report/?dimensions=video&format=json', {
            键入:GET,
            数据类型:JSON,
            beforeSend:功能(XHR){
                xhr.setRequestHeader(授权,承载$令牌)
            },
            完成:功能(RESP){
                执行console.log(RESP);
            },
            错误:函数(jqXHR,textStatus,errorThrown){
                执行console.log(textStatus);
            }
        }
    );
< / SCRIPT>
 

解决方案

  $。阿贾克斯({
        网址: 'https://data.brightcove.com/analytics-api/videocloud/accounts/867903724001/report/?dimensions=video&format=json',
      数据类型:JSONP,
     beforeSend:功能(XHR){
                xhr.setRequestHeader(授权,承载$令牌)
            },
      成功:功能(数据){
        的console.log(数据)
      },
     错误:函数(jqXHR,textStatus,errorThrown){
                    执行console.log(textStatus);
                }

    })
 

更改数据类型JSON到JSONP。既然你试图访问跨域你必须使用 jsop

Im trying to create a JSON request and I have the below script, for some reason I don't get a response. Can anyone help with this?

I haver my token but I have no idea where I need to put it?

    <script>
    $.ajax(
        'https://data.brightcove.com/analytics-api/videocloud/accounts/867903724001/report/?dimensions=video&format=json', {
            type: 'GET',
            dataType: 'json',
            beforeSend: function(xhr) {
                xhr.setRequestHeader("Authorization", "Bearer $token")
            },
            complete: function(resp) {
                console.log(resp);
            },
            error: function(jqXHR, textStatus, errorThrown) {
                console.log(textStatus);
            }
        }
    );
</script>

解决方案

 $.ajax({
        url: 'https://data.brightcove.com/analytics-api/videocloud/accounts/867903724001/report/?dimensions=video&format=json',
      dataType: 'JSONP',
     beforeSend: function(xhr) {
                xhr.setRequestHeader("Authorization", "Bearer $token")
            },
      success: function(data){
        console.log(data)
      },
     error: function(jqXHR, textStatus, errorThrown)   {
                    console.log(textStatus);
                }

    })

Change datatype json to jsonp. Since you trying to access cross domain you have to use jsop.

这篇关于阿贾克斯的Oauth 2.0访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆