我无法让 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 那么还有其他方法吗?
更新:刚刚发现您可以使用缓冲区发送多部分数据,所以这是我现在的代码
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 对其进行了测试并得到了相同的响应