using facebook requests
Can I send a request to friend from app without users promting to do so?
do i need special permission?
If I cannot send request from app without asking for it - can I ask user to send request to a friend without letting him choose which one? (app would specify to which he can send, using it 开发者_如何学JAVAfor a game).
Yes you can do this without any extended permissions. Check out the Facebook Dialog documentation for requests which explains and shows how the requests channel works with the Graph API Dialogs.
This sample also shows various ways of using app requests via Facebook's JS SDK.
<h1>requests</h1>
<button id="send-to-many">Send to Many</button>
<button id="custom-filters">Custom Filters</button>
<button id="send-to-one">Send to One</button>
<button id="send-app-to-user">Send App-to-User</button>
<button id="list-pending">List Pending</button>
<button id="clear-pending">Clear Pending</button>
<button id="clear-prompted">Clear Prompted</button>
<script>
document.getElementById('send-to-many').onclick = function() {
FB.ui({
method: 'apprequests',
message: 'You should learn more about the @[19292868552:Platform].'
}, Log.info.bind('send-to-many callback'));
}
document.getElementById('custom-filters').onclick = function() {
FB.ui({
method: 'apprequests',
message: 'Have you heard about @[184484190795:Rell]?',
data: 'invite-to-rell-42',
filters: [{name: 'Daaku', user_ids: ['1677846385']}, 'app_non_users', {name: 'Games People', user_ids: [703, 6203644]}]
}, Log.info.bind('send-to-many callback'));
}
document.getElementById('send-to-one').onclick = function() {
FB.ui({
method: 'apprequests',
message: 'A request especially for @[1677846385:Daaku].',
to: '1677846385',
data: 'send-to-one-42'
}, Log.info.bind('send-to-one callback'));
}
document.getElementById('send-app-to-user').onclick = function() {
FB.api(
'/me/apprequests',
{ message: 'From the app to the user.' },
'POST',
Log.info.bind('sent app-to-user request'));
}
document.getElementById('list-pending').onclick = function() {
FB.api('/me/apprequests', Log.info.bind('pending requests'));
}
document.getElementById('clear-pending').onclick = function() {
FB.api('/me/apprequests', function(response) {
var ids = [];
for (var i=0, l=response.data.length; i<l; i++) {
FB.api('/' + response.data[i].id, 'DELETE', Log.info.bind('clear requests'));
}
});
}
document.getElementById('clear-prompted').onclick = function() {
FB.api(
prompt('Enter the ID of the request to delete:'),
'DELETE',
Log.info.bind('delete request'));
}
</script>
精彩评论