这是Invite users to register at my site through Facebook的后续行动。
我现在仍在原型应用程序中工作。我设法使用Javascript API发送邀请,但我在解析响应对象时遇到问题。这是我的代码:
<a href="#">Send Application Request</a>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : '193005690721590',
status : true,
cookie : true,
xfbml : true
});
};
$('a').click(sendRequest);
function sendRequest() {
FB.ui({
method: 'apprequests',
message: 'Invitation to the test application!',
title: 'Send your friends an application request',
data: 'someCode'
},
function (response) {
if (response && response.request_ids) {
var requests = response.request_ids.join(',');
console.log(requests);
console.log(response);
var obj = $.parseJSON(response);
$.ajax({
url: '/Home/Parse',
type: 'post',
data: obj,
contentType: 'application/json; charset=utf-8',
success: function (data) {
if (data.result === 'ok') {
alert("Everything went fine");
//top.location.href = '/Home/About';
}
}
});
} else {
alert('canceled');
}
});
return false;
}
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
这是应该解析对象的action方法,但是现在我只想使用调试器检查对象的模式:
[HttpPost]
public ActionResult Parse(JsonObject response)
{
//parse the response object
return Json(new {result = "ok"});
}
但是,不幸的是,响应JsonObject似乎是空的!
那么我该如何让它发挥作用呢?
另一方面,是否可以使用Facebook C#SDK来执行请求对话框而不是使用Javascript API?