代码之家  ›  专栏  ›  技术社区  ›  Mechlar

使用jquery发布到YouTube API

  •  0
  • Mechlar  · 技术社区  · 15 年前

    我正在尝试向Google AuthSub发布YouTube的请求。我使用jquery进行Ajax发布等。当我发布时,会得到一个405错误:“405方法不允许”。

    这是我的JS:

    $.ajax({
    类型:“POST”,
    网址:“https://www.google.com/accounts/authsubrequest”,
    beforesend:函数(xhr){
    xhr.setrequestheader('x-gdata-key'、'key=“'+ytkey+'”');
    }
    成功:功能(OData){
    / /警报(ODATA);
    }
    作用域:“http://gdata.youtube.com”,
    阿尔特:“JSON”,
    下一步:'http:/'+globalbrand+'/sitecreator/view.do',
    会议:1
    (});
    < /代码> 
    
    

    我在API中为此使用的页面是here

    错误如下: 乌图布我使用jquery进行Ajax发布等。当我发布时,我得到一个405错误:“405方法不允许”。

    这是我的JS:

       $.ajax({
          type: 'POST',
          url: "https://www.google.com/accounts/AuthSubRequest",
          beforeSend: function(xhr){
             xhr.setRequestHeader('X-GData-Key', 'key="' + ytKey + '"');
          },
          success: function(oData){
             //alert(oData);
          },
          scope: 'http://gdata.youtube.com',
          alt: 'json',
          next: 'http://' + globalBrand + '/sitecreator/view.do',
          session: 1
       });
    

    我在API中为此使用的页面是here.

    错误如下:

    3 回复  |  直到 14 年前
        1
  •  1
  •   prodigitalson    15 年前

    请求的数据参数放错了位置,请参阅以下内容:

    $.ajax({
          type: 'POST',
          url: "https://www.google.com/accounts/AuthSubRequest",
          data: {
            scope: 'http://gdata.youtube.com',
            alt: 'json',
            next: 'http://' + globalBrand + '/sitecreator/view.do',
            session: 1
          },
          beforeSend: function(xhr){
             xhr.setRequestHeader('X-GData-Key', 'key="' + ytKey + '"');
          },
          success: function(oData){
             //alert(oData);
          }
    
       });
    

    现在,这可能是你另外做错了什么,但这确实需要纠正。

        2
  •  0
  •   Mechlar    15 年前

    啊,这是解决这个问题的办法。如果我使用构建的URL发出请求,并将其作为一个href分配给一个锚,或者在window.open()中调用它,那么它就工作了。

    window.open('https://www.google.com/accounts/AuthSubRequest?scope=http://gdata.youtube.com&next=http://' + globalBrand + '/sitecreator/view.do&session=1');
    

    至于为什么jquery的Ajax方法被拒绝,我不知道。这似乎是个问题 elsewhere 也。

        3
  •  0
  •   renedet    14 年前

    jquery中错误HTTP头选项的解决方案,此请求对我来说是正常的:

    var word = 'search+word';
    $.ajax({
            type: "GET",
            url: "http://gdata.youtube.com/feeds/api/videos?q="+word+"&max-results=10&alt=json-in-script&format=5,
            cache: false,
            dataType:'jsonp',
            success: function(data){
                    //json 'data' var treatment
            },
           error: function(XMLHttpRequest, textStatus, errorThrown, data){
                alert("Not able to fetch the data due to feed unavailability!!!");
            }
    });
    

    参考文献: http://www.mohammedarif.com/?p=180