2011-09-18 202 views
17

我想使用Node.js发布状态更新到Facebook组。这似乎Node.js的不会发送标题...Node.js HTTPS POST请求标头

var https = require('https'); 

var options = { 
    host: 'graph.facebook.com', 
    port: 443, 
    path: '/'+group_id+'/feed?access_token='+access_token, 
    method: 'POST', 
    headers: { 'message': text } 
}; 

var req = https.request(options, function(res) { 
    console.log("statusCode: ", res.statusCode); 
    console.log("headers: ", res.headers); 

    res.on('data', function(d) { 
     process.stdout.write(d); 
    }); 
}); 

req.end(); 

这是日志数据:

statusCode: 400 
headers: { 'cache-control': 'no-store', 
    'content-type': 'text/javascript; charset=UTF-8', 
    expires: 'Sat, 01 Jan 2000 00:00:00 GMT', 
    p3p: 'CP="Facebook does not have a P3P policy. Learn why here: http://fb.me/p3p"', 
    pragma: 'no-cache', 
    'www-authenticate': 'OAuth "Facebook Platform" "invalid_request" "(#100) A post to a group must have at least a message or attachment"', 
    'x-fb-rev': '443252', 
    'set-cookie': [ 'datr=removed; expires=Tue, 17-Sep-2013 12:18:08 GMT; path=/; domain=.facebook.com; httponly' ], 
    'x-fb-server': '10.62.5.40', 
    connection: 'close', 
    date: 'Sun, 18 Sep 2011 12:18:08 GMT', 
    'content-length': '115' } 
{"error":{"message":"(#100) A post to a group must have at least a message or attachment","type":"OAuthException"}} 
+0

这应该有所帮助:http://criso.github.com/fbgraph/ –

回答

17

我认为你需要发送邮件(您的变量的内容,称为“文” )在你的要求正文,而不是。有关如何执行此操作的示例,请参阅this answer