【发布时间】:2015-08-11 23:44:52
【问题描述】:
我无法让 App Links 与 Parse 一起使用。
由于我的应用程序仅是移动应用程序,因此我想使用 Facebook 的移动托管 API。 并且由于您需要发送您的 Facebook 应用程序密钥以及我想使用 Parse Cloud Code 的请求。
我在 Facebook 文档上只能找到如何使用 cURL:
curl https://graph.facebook.com/app/app_link_hosts \
-F access_token="APP_ACCESS_TOKEN" \
-F name="iOS App Link Object Example" \
-F ios=' [
{
"url" : "sharesample://story/1234",
"app_store_id" : 12345,
"app_name" : "ShareSample",
}, ]' \
-F web=' {
"should_fallback" : false, }'
这就是我在云代码中想到的
Parse.Cloud.httpRequest({
method: 'POST',
url: 'https://graph.facebook.com/app/app_link_hosts',
headers: {
'Content-Type': 'multipart/form-data'
},
body: {
access_token : "APP_ACCESS_TOKEN",
name : "iOS App Link Object Example",
ios : '[{"url" : "sharesample://story/1234","app_store_id" : 12345,"app_name" : "ShareSample",},]',
web : '{"should_fallback" : false,}'
}
我得到的响应是:请求失败,响应代码为 400
现在我刚刚读到 Parse.Cloud.httpRequest 不支持 multipart/form-data 那么还有其他方法可以做到这一点吗?
更新:刚刚发现可以使用 Buffer 发送多部分数据, 所以这是我现在的代码
var Buffer = require('buffer').Buffer;
var access_token = new Buffer('APP_ACCESS_TOKEN','utf8');
var name = new Buffer('iOS App Link Object Example','utf8');
var ios = new Buffer('[{"url" : "sharesample://story/1234","app_store_id" : 12345,"app_name" : "ShareSample",},]','utf8');
var web = new Buffer('{"should_fallback" : false,}','utf8');
var contentBuffer = Buffer.concat([access_token, name, ios, web]);
Parse.Cloud.httpRequest({
url: 'https://graph.facebook.com/app/app_link_hosts',
method: 'POST',
headers: {
'Content-Type': 'text/html; charset=utf-8'
},
body: contentBuffer
}
但是我仍然得到相同的结果:(
update2:让它与内容类型 application/x-www-form-urlencoded 和正常正文一起使用。但我认为错误出在我的参数中,因为我用 curl 对其进行了测试并得到了相同的响应
【问题讨论】:
标签: javascript facebook parse-platform applinks