如何以访客身份从自定义网页在 Facebook 粉丝页面上发帖(PHP 代码)
我希望我的网站的访问者可以从我的网站页面在我的 Facebook 粉丝页面上发帖。发帖前必须进行用户身份验证。我怎样才能做到这一点?目前我只能以管理员身份发布到我的 Facebook 粉丝页面。
我使用的代码如下。
define("FB_APIKEY", "xxxxxxxx");
define("FB_SECRET", "xxxxxxxx");
$pageid = xxxxxxxxxxxx; //replace it by your desire facebook page id
require_once("src/facebook.php");
require_once("php/facebook.php");
$facebook = new Facebook(array('appId' => "xxxxxxxxxxxxxxxx",'secret' =>"xxxxxxxxxxxxxxxxxxx",));
$user = $facebook->getUser();
$user = (string)$user;
if ($user!="") {
// The user is logged in
try {
$user_profile = $facebook->api("/".$user);
$fb = new Facebook1(FB_APIKEY, FB_SECRET);
$userId = $user;
$targetId = "xxxxxxxxx"; // Page ID of the fan page
$fb->api_client->user = $userId;
$fb->api_client->session_key = $sessionKey;
$fb->api_client->expires = 0;
$fb->set_user($userId, $sessionKey); // set the 'logged in' user
// first, check if this UID is a valid user of this application
$isAppUser = $fb->api_client->users_isAppUser($userId);
// second, check whether this user has set the permission needed
// since my app need these permissions: offline_access, read_stream, publish_stream
$offline_access = $fb->api_client->users_hasAppPermission('offline_access', $userId);
$message="Test message for fabudeal";
// if everything is okay...
if ($offline_access && $isAppUser) {
// write to this user's Wall
$fb->api_client->stream_publish($message, $attachment, null, $targetId, $userId);
}
} catch (FacebookApiException $e) {
$user = null;
}
}
请帮我解决这个问题......
I want to the visitors of my website to post on my facebook fan page, from my website's page. User authentication has to be done before posting. How can I do that? Currently I can post into my fb fan page as admin only.
The code which Im using is give below.
define("FB_APIKEY", "xxxxxxxx");
define("FB_SECRET", "xxxxxxxx");
$pageid = xxxxxxxxxxxx; //replace it by your desire facebook page id
require_once("src/facebook.php");
require_once("php/facebook.php");
$facebook = new Facebook(array('appId' => "xxxxxxxxxxxxxxxx",'secret' =>"xxxxxxxxxxxxxxxxxxx",));
$user = $facebook->getUser();
$user = (string)$user;
if ($user!="") {
// The user is logged in
try {
$user_profile = $facebook->api("/".$user);
$fb = new Facebook1(FB_APIKEY, FB_SECRET);
$userId = $user;
$targetId = "xxxxxxxxx"; // Page ID of the fan page
$fb->api_client->user = $userId;
$fb->api_client->session_key = $sessionKey;
$fb->api_client->expires = 0;
$fb->set_user($userId, $sessionKey); // set the 'logged in' user
// first, check if this UID is a valid user of this application
$isAppUser = $fb->api_client->users_isAppUser($userId);
// second, check whether this user has set the permission needed
// since my app need these permissions: offline_access, read_stream, publish_stream
$offline_access = $fb->api_client->users_hasAppPermission('offline_access', $userId);
$message="Test message for fabudeal";
// if everything is okay...
if ($offline_access && $isAppUser) {
// write to this user's Wall
$fb->api_client->stream_publish($message, $attachment, null, $targetId, $userId);
}
} catch (FacebookApiException $e) {
$user = null;
}
}
Please help me to fix this.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经使用 FB javascript SDK 找到了解决我的问题的方法。我使用的代码如下。认为有人可能会发现它有用。
谢谢
I have found a solution for my problem using FB javascript SDK. The code which I used is give below. Thought somebody might find it useful.
Thanks