-1
我想讓我的網站訪問者在我的Facebook粉絲頁面上發佈,從我的網站頁面。用戶認證必須在發佈前完成。我怎樣才能做到這一點?目前我只能以管理員身份登錄到我的fb粉絲頁面。如何作爲訪問者在自定義網頁上發佈在Facebook粉絲頁面(PHP代碼)
我使用的代碼如下。
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;
}
}
請幫我解決這個問題.....