Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Facebook';s移动托管API,带有解析应用程序链接的云代码_Javascript_Facebook_Parse Platform_Applinks - Fatal编程技术网

Javascript 使用Facebook';s移动托管API,带有解析应用程序链接的云代码

Javascript 使用Facebook';s移动托管API,带有解析应用程序链接的云代码,javascript,facebook,parse-platform,applinks,Javascript,Facebook,Parse Platform,Applinks,我在获取应用程序链接和解析时遇到问题 因为我的应用程序是移动的,所以我想使用Facebook的移动托管API。 既然你需要发送你的Facebook应用程序机密和请求,我想用解析云代码 我在Facebook文档中找到的只是如何使用cURL: curl https://graph.facebook.com/app/app_link_hosts \ -F access_token="APP_ACCESS_TOKEN" \ -F name="iOS App Link Object Example" \

我在获取应用程序链接和解析时遇到问题

因为我的应用程序是移动的,所以我想使用Facebook的移动托管API。 既然你需要发送你的Facebook应用程序机密和请求,我想用解析云代码

我在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不支持多部分/表单数据 那么还有别的方法吗

更新:刚刚发现你可以用缓冲区发送多部分数据, 这就是我现在的代码

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
}
然而,我仍然得到同样的结果:(


更新2:使用内容类型应用程序/x-www-form-urlencoded和正常正文使其正常工作。但我认为错误在我的参数中的某个地方,因为我使用curl对其进行了测试,得到了相同的响应。我花了几个小时,但我最终使其正常工作:

// Returns the canonical url, like https://fb.me/....
Parse.Cloud.define("createAppLink", function(request, response) {
    // see https://developers.facebook.com/docs/graph-api/reference/v2.5/app/app_link_hosts

    var storyId = request.params.storyId + ''; // param identifying a single "post"
    var appId = 'APP_ID';
    var appSec = 'APP_SECRET';
    var appToken = appId + '|' + appSec; // your app token

    Parse.Cloud.httpRequest({
        url: 'https://graph.facebook.com/app/app_link_hosts',
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({ // you need to stringify it
            access_token: appToken,
            name: 'LINK TO ' + storyId, // it is needed but not public
            android: [{
                url: 'app://story/' + storyId, // deep link url
                package: 'com.package', // your package name
                app_name: 'APP' // your app name
            }],
            web: { should_fallback: 'false' }
        })
    }).then(function(httpResponse) {
        // We get an id, by which we can fetch
        // the canonical url with a get request
        var data = JSON.parse(httpResponse.text);
        var id = data.id;
        return Parse.Cloud.httpRequest({
            url: 'https://graph.facebook.com/' + id,
            method: 'GET',
            headers: {
                'Content-Type': 'application/json'
            },
            params: {
                access_token: appToken,
                fields: 'canonical_url',
                pretty: 'true'
            }
        });
    }).then(function(httpResponse) {
        var data = JSON.parse(httpResponse.text);
        var canonicalUrl = data.canonical_url;
        response.success(canonicalUrl);

    }, function(error) {
        response.error(error);
    })
});