问题
This is a follow up to Invite users to register at my site through Facebook.
I'm still working within a prototype application for now. I managed to use the Javascript API to send out invitations, but I'm having problems parsing the response object. Here's my code:
<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>
And here's the action method that is supposed to parse the object, but for now I just want to check out the schema of the object using the debugger:
[HttpPost]
public ActionResult Parse(JsonObject response)
{
//parse the response object
return Json(new {result = "ok"});
}
But, unfortunately, the response JsonObject appears to be null!
So how do I get this to work?
On a side not, is it possible to use the Facebook C# SDK to do the Request dialog stuff instead of using the Javascript API?
来源:https://stackoverflow.com/questions/5975696/sending-facebook-invitations-tracking-invitation-codes