I have developed a Facebook application using the Facebook JavaScript SDK and Android PhoneGap. I am able to post messages to the Facebook wall, but now I want to include a permission dialog before posting the message. The goal is to only allow the message to be posted if the user clicks on the "Allow" button in the permission dialog; if they click on "Don't Allow," the message should not be posted. Here is the code snippet:
<body>
<div id='fb-root'></div>
<script src='all.js'></script>
<input type="text" value="User ID" name="user_ids" />
<p><a onclick='postToFeed(); return false;'>Post to Feed</a></p>
<p id='msg'></p>
<script>
FB.init({appId: "xxxxxxxx", status: true, cookie: true});
function postToFeed()
{
var user_ids = document.getElementsByName("user_ids")[0].value;
alert(user_ids);
FB.api('/me/feed', 'post', { message: user_ids}, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}
</script>
</body>
The above code is currently hosted on a server. In the PhoneGap (index.html) app, I call this URL using the window.open method. When the button is clicked (and the text value from the textbox is retrieved), the message should be posted on the wall. Now, I am looking for suggestions or ideas on how to implement a permission dialog for this functionality or how to pass {perms:'publish_stream'} in the FB.api('/me/feed') call.
Any help or suggestions would be greatly appreciated. Thank you.