对 Picasa API 的 POST 请求 [英] POST request to Picasa API
问题描述
我一直在为 Picasa API 上的 POST 苦苦挣扎.代码如下:
$.ajax({类型:POST",网址:'https://picasaweb.google.com/data/feed/api/user/' + uid + '/albumid/' + album_id + '/photoid/' + photo_id,跨域:真,数据:{内容:内容},成功:函数(){警报(成功");},错误:函数(){警报('失败!');}});
我已经通过 GET 检索了一些信息,没有问题.
现在是有趣的部分,当我尝试使用 Google 测试该服务时发生此错误:
XMLHttpRequest 无法加载https://picasaweb.google.com/data/feed/api/user/userid/albumid/albumid/photoid/photoid?content=foo%bar.不允许 Origin http://localhost:3000访问控制允许来源
.
当我在 Firefox 中尝试时,请求标头方法更改为 OPTIONS
并且状态为 204: no content
.
此外,我尝试将 datatype
更改为 jsonp
但随后 HTTP 方法更改为 GET
并检索有关图片的信息.
Access-Control-Allow-Origin
即将到来,因为您正在对与当前服务器不同的服务器进行 ajax 调用领域.阅读更多此处
jsonp
对 POST
请求没有帮助,因为您只能使用 jsonp
发出 GET
请求.>
恕我直言,您应该尝试从服务器端而不是客户端脚本发出 POST 请求.
I'v been struggling with POST on the Picasa API. Here's code:
$.ajax({
type: "POST",
url: 'https://picasaweb.google.com/data/feed/api/user/' + uid + '/albumid/' + album_id + '/photoid/' + photo_id,
crossDomain: true,
data: { content: content },
success: function() { alert("Success"); },
error: function() { alert('Failed!'); }
});
I've already retrieved some information via GET without problems.
Now comes the fun part, when I try to test the service with Google this error occurs:
XMLHttpRequest cannot load
https://picasaweb.google.com/data/feed/api/user/userid/albumid/albumid/photoid/photoid?content=foo%bar.
Origin http://localhost:3000 is not allowed by
Access-Control-Allow-Origin
.
And when I try in Firefox the request header method is changed to OPTIONS
and status is 204: no content
.
Also, I've tried to change datatype
to jsonp
but then HTTP method changes to GET
and it retrieves information about the picture.
Access-Control-Allow-Origin
is coming because your are making a ajax call to a server which is not same as your current domain.
Read more here
jsonp
will not help for POST
request because you can only make GET
request with jsonp
.
IMHO you should try to make the POST request from server side instead of client side script.
这篇关于对 Picasa API 的 POST 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!