使用Facebook一批请求JavaScript API第 [英] using facebook batch request javascript api
本文介绍了使用Facebook一批请求JavaScript API第的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试着发送一批请求图形API,并在第二个请求的响应收到错误:
{
错误:{
消息:(#100)丢失邮件或附件,
类型:OAuthException,
code:100
}
}
谁能告诉我,我究竟做错了什么?
下面是code我使用:
VAR选择采用= {
消息:有些消息,
名称:文章名称,
链接:URL,
说明:该职位说明',
图片:网址形象
};FB.api('/','POST',{
批:
{方法:GET,relative_url:我/朋友},
{方法:POST,relative_url:我/饲料,身体:选择采用}
]
},函数(响应){
的console.log(响应);
});
解决方案
像沙龙说,你需要把体内场的URL连接codeD的方式。
您可以做到这一点简单的使用jQuery,如:
VAR选择采用= {
消息:有些消息,
名称:文章名称,
链接:URL,
说明:该职位说明',
图片:网址形象
};FB.api('/','POST',{
批:
{方法:GET,relative_url:我/朋友},
{方法:POST,relative_url:我/饲料,身体:$ .PARAM(选)}
]
},函数(响应){
的console.log(响应);
});
作品不错。
Im trying to send batch request to graph api, and getting error in the response for the second request:
"{
"error": {
"message": "(#100) Missing message or attachment",
"type": "OAuthException",
"code": 100
}
}"
Can anyone tell me what am I doing wrong?
Here is the code I use:
var opts = {
message : 'Some message',
name : 'Post Name',
link : 'url',
description : 'The post Description',
picture : 'url to image'
};
FB.api('/', 'POST', {
batch: [
{ method: 'GET', relative_url: 'me/friends'},
{ method: "POST",relative_url: "me/feed", body : opts }
]
}, function (response) {
console.log(response);
});
解决方案
Like Sharon said, you need to put the body field in a url encoded way.
You can do it simple with jquery, like:
var opts = {
message : 'Some message',
name : 'Post Name',
link : 'url',
description : 'The post Description',
picture : 'url to image'
};
FB.api('/', 'POST', {
batch: [
{ method: 'GET', relative_url: 'me/friends'},
{ method: "POST",relative_url: "me/feed", body : $.param(opts) }
]
}, function (response) {
console.log(response);
});
Works good.
这篇关于使用Facebook一批请求JavaScript API第的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文