【问题标题】:Want to POST Text to Tumblr想在 Tumblr 上发布文本
【发布时间】:2013-06-17 12:52:29
【问题描述】:

我能够为 Tumblr 博客执行 GET 方法, 但是每当我尝试为 Tumblr 执行 POST 方法时,我都会收到一个错误::

({"meta":{"status":401,"msg":"Not Authorized"},"response":[]});

我正在为 Ajax Post 使用以下代码::

$.ajax({
    type: 'POST',
    url: 'https://api.tumblr.com/v2/blog/firstblgpsa.tumblr.com/post',
    dataType: "jsonp",
    data: {
        api_key: "*key here*",
        type: 'text',
        title: 'First_Post',
        body:'This is My First Post to Tumblr.'
    },
    success:function(){
        alert("Blog Posted Successfully!!");
    }
}) 

【问题讨论】:

  • jsonp 不支持 POST 方法。更准确地说,你不能在跨域ajax中使用GET以外的方法。 stackoverflow.com/questions/4508198/…
  • 但是如果我想在我的 Tumblr 博客中发布一些文字该怎么办。
  • 我认为您不希望其他人开始使用您的密钥并代表您上传内容,删除了您的密钥。

标签: javascript jquery ajax tumblr


【解决方案1】:

在客户端(在浏览器中),默认情况下允许您仅使用 GET 请求。这是same origin policy。有一些技巧可以解决这个问题,但我不建议这样做。

JSONP 甚至不可能,请参阅q: How to use type: “POST” in jsonp ajax call 问题中的更多详细信息

你应该怎么做:
执行此类操作的正确方法是将请求发送到您的域服务器(后端),然后直接使用 phpruby 从后端服务器向 tumblr 发出请求,或者您到达那里。

【讨论】:

  • 但如果我没有在我的 AJAX POST 方法中使用该数据类型,那么我也无法在 Tumblr 上创建新博客
猜你喜欢
  • 2013-05-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-16
  • 2012-09-09
  • 2019-12-11
  • 2014-06-06
  • 1970-01-01
相关资源
最近更新 更多