Javascript Facebook营销API“node js”;“讯息”:&引用;不支持的post请求。”&引用;“类型”为:&引用;“图形方法异常”&引用;代码";:100
我正在尝试使用Facebook营销API在Node.js中创建新的广告活动 我已成功从此url获取访问令牌:Javascript Facebook营销API“node js”;“讯息”:&引用;不支持的post请求。”&引用;“类型”为:&引用;“图形方法异常”&引用;代码";:100,javascript,node.js,facebook,facebook-graph-api,Javascript,Node.js,Facebook,Facebook Graph Api,我正在尝试使用Facebook营销API在Node.js中创建新的广告活动 我已成功从此url获取访问令牌: var fbApi = { 'method': 'GET', 'url' : 'https://graph.facebook.com/oauth/access_token?client_id=MYCLIENTID&client_secret=MYSECRET&grant_type=client_credentials' } 然后我提出这个POST请求(使用“请求”模块)
var fbApi = {
'method': 'GET',
'url' : 'https://graph.facebook.com/oauth/access_token?client_id=MYCLIENTID&client_secret=MYSECRET&grant_type=client_credentials'
}
然后我提出这个POST请求(使用“请求”模块)。
我正在发布“名称”和“活动组状态”的值,我知道这是必需的值
我正在向端点发帖
https://graph.facebook.com/<API_VERSION>/act_<AD_ACCOUNT_ID>/adcampaign_groups
完整代码(敏感信息替换为虚拟数据):
我看到的错误响应:
request2 says ---- {"error":{"message":"Unsupported post request.","type":"GraphMethodException","code":100}}
在此之前,我得到了一个关于权限的错误,另一个错误说“name”值是必需的。这些问题已经解决。所以我相信我有正确的访问权限,Facebook正在获取请求的正文内容
非常感谢您的帮助 如果您查看这些示例,它们在curl中使用-F选项
-F, --form <name=content>
(HTTP) This lets curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST data using the Content-Type multipart/form-data according to RFC 2388. This
enables uploading of binary files etc. To force the 'content' part to be a file, prefix the file name with an @ sign. To just get the content part from a file, prefix the file name with the symbol <.
The difference between @ and < is then that @ makes a file get attached in the post as a file upload, while the < makes a text field and just get the contents for that text field from a file.
此代码示例未经测试。我不熟悉API,但听起来您的请求确实不正确。。。其他API端点可以工作吗?
request2 says ---- {"error":{"message":"Unsupported post request.","type":"GraphMethodException","code":100}}
-F, --form <name=content>
(HTTP) This lets curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST data using the Content-Type multipart/form-data according to RFC 2388. This
enables uploading of binary files etc. To force the 'content' part to be a file, prefix the file name with an @ sign. To just get the content part from a file, prefix the file name with the symbol <.
The difference between @ and < is then that @ makes a file get attached in the post as a file upload, while the < makes a text field and just get the contents for that text field from a file.
var request = require('request');
var fbOptions = {
'name' : 'test2',
'campaign_group_status' : 'PAUSED'
}
// var fbOptionsString = JSON.stringify(fbOptions);
var fbPost = {
'uri' : ' https://graph.facebook.com/v2.3/act_5374356645419299/adcampaign_groups?access_token=56345345453773242|iert_arfwYfwfwxD-pLxHcpASFTNm',
'method': 'POST',
'headers': {
'Content-Type' : 'application/json',
},
'formData' : fbOptions
}
request(fbPost, function(error, response, body){
console.log('request says ----', body);
})