如何从我自己的管理页面(CMS)发布到我的Facebook墙?
问题描述:
如何从我的管理页面向我的Facebook页面发布普通帖子,以便将内容上传到我的网页?如何从我自己的管理页面(CMS)发布到我的Facebook墙?
因此,我从我的CMS上传内容到我的网页,并在我的管理页面中显示我上传的内容旁边的位置我想要一个可以将该帖子发布到我的Facebook墙上的按钮。作为一个普通的职位,而不是像LIKE职位或评论职位!
答
首先,您需要创建一个Facebook应用程序。 然后你会得到一个应用程序ID和一个秘密密钥。
使用这个细节,你可以使用Facebook的PHP库 做后期到乌尔墙壁或U可以使用下面的函数
<?php
function doWallPost($postName='',$postMessage='',$postLink='',$postCaption='',$postDescription='')
{
$FB_APP_ID='xxxxxxxxxxxxxxxxxxxxxxxx';
$FB_APP_SECRET='xxxxxxxxxxxxxxxxxxxxxxxxxxx';
$APP_RETURN_URL=((substr($_SERVER['SERVER_PROTOCOL'],0,4)=="HTTP")?"http://":"https://").$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
$code = $_REQUEST["code"];
if(empty($code))
{
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id=".$FB_APP_ID."&redirect_uri=".$APP_RETURN_URL."&scope=publish_stream";
header("Location:$dialog_url");
}
$token_url = "https://graph.facebook.com/oauth/access_token?client_id=".$FB_APP_ID."&redirect_uri=".urlencode($APP_RETURN_URL)."&client_secret=".$FB_APP_SECRET."&code=".$code;
$access_token = file_get_contents($token_url);
$param1=explode("&",$access_token);
$param2=explode("=",$param1[0]);
$FB_ACCESS_TOKEN=$param2[1];
$url = "https://graph.facebook.com/me/feed";
$attachment = array( 'access_token' => $FB_ACCESS_TOKEN,
'name' => $postName,
'link' => $postLink,
'description' => $postDescription,
'message' => $postMessage,
'caption' => $postCaption,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
$result=curl_exec($ch);
header('Content-type:text/html');
curl_close($ch);
return $result
}
?>
答
功能postonwall(){ // showLoader(true);
FB.api('/me/feed', 'post', { message : "testtext.", link : 'http://www.mydomain.se', picture : 'http://www.mydomain.se/image.jpg', name : 'iOS Apps & Games', description : 'Checkout iOS apps and games from iThinkdiff.net. I found some of them are just awesome!' }, function(response) { // showLoader(false); if (!response || response.error) { alert('Error occured'); } else { //alert('Post ID: ' + response.id); alert('Success: Content Published'); } }); }
非常感谢AKHIL 但我不能使用PHP我怕我的服务器上,是有什么simular jQuery中 - JavaScript的? 我在上面的代码中看到了dialog_url,上面的贴子是在我的墙上,所以它看起来就像我从Facebook内部发布它? 所以我可以发布大图片等? 我不希望它发布评论,不喜欢这个例子:http://demo.lookmywebpage.com/publish-on-facebook-wall/ 我只想确保在我开始之前:-) 谢谢再次! – 2012-02-22 19:10:36
只需尝试一个演示与此,发布到你的fb墙的东西,我希望一个尝试将清除所有你的疑惑 – 2012-02-23 04:54:36
好的谢谢你的帮助,但这是PHP代码,不是吗?而我的服务器不支持PHP。 而我不知道我是否理解它,如果我想从我的数据库中获取postmessage和其他值,我在哪里放置它?我也想同时发送图片,我该怎么做? 对不起:-) – 2012-02-23 07:20:10