我正在使用Nick Baker's(webtechnick)CakePHP/Facebook插件,它非常棒,效果很棒,但是我有一个问题,我似乎甚至无法接近答案。Cakephp Facebook插件 - 通过动作共享
我该如何绕过使用分享按钮并通过操作直接共享?
例如,我通过我的网站发布帖子,帖子添加到数据库,它也会通过操作向登录用户Twitter帐户发送帖子。我怎样才能让这个动作把手分享给我的FB账户(已经建立了连接)?我尝试了第一件事,我认为任何人都明显会尝试$ this-> Facebook-> share()直接在动作中,也无济于事......
任何想法或解决方案都会有很大的帮助...
更新后的回答
Thx帮助spooney。我投了你的答案,因为你可以从我所知道的100%中找出答案。我正在加载JS SDK。
function init($options = null, $reload = true) {
if (empty($options)) {
$options = array();
}
if ($appId = FacebookInfo::getConfig('appId')) {
$session = json_encode($this->Session->read('FB.Session'));
if ($reload) {
$callback = "FB.Event.subscribe('auth.login',function(){window.location.reload()});";
} else {
$callback = "if(typeof(facebookReady)=='function'){facebookReady()}";
}
$callback .= "FB.Event.subscribe('auth.logout',function() {window.location = '/bastards/users/logout'});";
$init = '<div id="fb-root"></div>';
$init .= $this->Html->scriptBlock(
<<<JS
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 // use Oauth
});
{$callback}
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/{$this->locale}/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
JS
, $options);
return $init;
} else {
return "<span class='error'>No Facebook configuration detected. Please add the facebook configuration file to your config folder.</span>";
}
}
我没有问题拉入用户信息和所有的工作。我已经从我的网站完成张贴到FB,但它只是通过链接,使用FB.ui ...
<a href="#" onClick="publishStory();" class="sendFeed"><br><font style="color:#FFF; text-decoration:none;padding-left:27px;">post to wall</font></a><br>
<script>
function publishStory() {
FB.ui({
method: 'feed',
name: 'message name',
caption: 'message caption ',
description: 'description goes here',
link: 'the url current page',
picture: 'if you want to add an image'
},
function(response) {
console.log('publishStory response: ', response);
});
return false;
}
</script>
我曾尝试更换上面的代码...
<a href="#" onClick="publishStory();" class="sendFeed"><br><font style="color:#FFF; text-decoration:none;padding-left:27px;">post to wall</font></a><br>
<script>
function publishStory() {
var body = 'Reading JS SDK documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
}
</script>
但每次都会出错。
我也应该在那里说用户FB墙上的帖子并不是真的来自网站persay,它是用户在自己墙上的帖子,基本上说,“我在ladala.com上发了一篇文章,你应该去看看。“
所以现在我需要弄清楚如何通过提交帖子的动作来运行FB.ui。
我知道JS SDK支持这种功能。正在使用它的可能性? –
要完全诚实的呕吐我不知道...你说的是,http://developers.facebook.com/docs/reference/javascript/,对吗? –
是的。使用JS SDK我可以调用API,比如人们阅读过的文章或者他们看过的视频,而且实现起来非常简单。您还可以提示用户将内容分享到他们的墙上(http://developers.facebook.com/docs/reference/javascript/FB.ui/) (https://developers.facebook.com/docs/reference/)对话框/进料/)。我不完全确定这是你正在寻找什么,或者如果它有意义的实现到你的应用程序,虽然。 –