Как я могу опубликовать на стене друзей, используя фреймворк javascript SDK?
Размещение на стене друзей с помощью facebook javascript sdk
Ответ 1
В дополнение к @ifaour ответу на FB.api
...
- Задайте параметры oauth и status в
FB.init
- Запросить расширенное разрешение publish_stream через
FB.login
Другие ресурсы:
с использованием публикации в facebook
Полный пример...
<script>
window.fbAsyncInit = function()
{
FB.init({
appId : 'APP_ID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true , // parse XFBML
oauth : true // Enable oauth authentication
});
FB.login(function(response)
{
if (response.authResponse)
{
alert('Logged in!');
// Post message to friend wall
var opts = {
message : 'Post message',
name : '',
link : 'http://www....',
description : 'Description here',
picture : 'http://domain.com/pic.jpg'
};
FB.api('/FRIEND_ID/feed', 'post', opts, function(response)
{
if (!response || response.error)
{
alert('Posting error occured');
}
else
{
alert('Success - Post ID: ' + response.id);
}
});
}
else
{
alert('Not logged in');
}
}, { scope : 'publish_stream' });
};
</script>
<!-- FACEBOOK -->
<div id="fb-root"></div>
<script>
(function() {
var e = document.createElement('script');
// replacing with an older version until FB fixes the cancel-login bug
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
//e.src = 'scripts/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
<!-- END-OF-FACEBOOK -->
Ответ 2
Вам нужно использовать метод FB.api
, например:
var body = 'Reading Connect JS documentation';
FB.api('/FRIEND_ID/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
Ответ 3
<script type="text/javascript">
var friendIds=new Array();;
window.fbAsyncInit = function()
{
FB.init
(
{
appId : 'appid',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true , // parse XFBML
oauth : true // Enable oauth authentication
}
);
FB.login(function(response)
{
if (response.authResponse)
{
console.log('Welcome! Fetching your information.... ');
FB.api('/me/friends/', function(response)
{
for(i=0;i<20;i++)
{
console.log('Good to see you, ' + response.data[i].name + '.');
console.log(response.data[i].id);
friendIds[i]=response.data[i].id;
}
});
}
else
{
console.log('User cancelled login or did not fully authorize.');
}
});
};
$(document).ready(function ()
{
$('#shareonfacebook').click(function(e)
{
e.preventDefault();
var publish =
{
method: 'stream.publish',
name: 'DvimayPostPhoto',
link: 'http://localhost/FaceBook/index.html',
picture: 'http://www.fbrell.com/public/f8.jpg',
caption: 'hey how is my Application ? tell me dude',
description: 'hey how is my Application ?',
from: 'myid',
message: ''
};
for(i=0;i<20;i++)
{
publish.target_id = friendIds[i];
FB.ui(publish);
}
//publish.target_id = 'rupali.7';
//FB.ui(publish);
});
});
</script>