How to post to user's wall on Facebook from a Silverlight app running inside Facebook in an iFrame?
I have a Facebook app set up where the app is running in an iFrame. That iFrame just contains an index.html which wraps a Silverlight app.
It all runs great, but I now would like to be able to post to the user's wall from inside the Silverlight app. It seems to me like there might be two ways I could do this:
- Use the Silverlight Facebook SDK to spawn a sub-browser page, authenticate, retrieve tokens and then post to the wall
- Put something in my wrapper index.html that delivers the necessary app tokens to my Silverlight control, and then call back from that control (into Javascript?) to do the posting
The second looks like a much mor开发者_如何学运维e appealing option, but the first is the only one I know how to do. Anyone got any better experiences/thoughts here?
Chris
You could do something like this in your page:
<script>
FB.getLoginStatus(function(response) {
if (response.session) {
// Substitute with the proper stuff in your silverlight app
mySilverlightFBApp.setFBSessionStuff(
response.session.access_token,
response.session.expires,
response.session.uid
);
}
});
</script>
There are additional fields in the session object (but not sure you want to do that). BTW, the getLoginStatus function doesn't log the user in it only checks their status. Since they are (presumably) using your app and have (also presumably) allowed the app, this should just work. (you do need to have them login and allow the app.. and you will potentially need to ask for permissions.. which in this case you want to publish to their feed). Your index page will also need to include the FB Javascript (and have it properly set up).
Check out the FB docs here for more info: http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/
Perhaps: 3) Use the facebook javascript SDK to let the user publish a stream story themselves? If you've already got the fb.init functions etc all setup, then just call (something like)this (the part at the bottom is for tracking posts, if you want):
FB.ui(
{
display:'iframe',
method: 'stream.publish',
caption: 'blah',
description: 'hey there. wow.,
name: 'yo',
link: 'http://foo.com',
picture: 'http://image.com/blah.gif',
action_links: [
{
text: 'Try for free',
href: 'http://foo.com'
}],
},
function (response) {
if (response && response.post_id) {
var URL = '/pages/ajax_InsertUserFacebookPost.aspx?';
URL += 'facebookpostid=' + response.post_id;
//alert(URL);
$.ajax({
type: "GET",
url: URL,
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true
});
} else {
//alert('Post was not published.');
}
}
);
精彩评论