HTTP 메소드를 선택하고 선택적 매개 변수를 설정하여 API를 호출 할 수 있습니다.
$facebook->api('/me/feed/', 'post', array(
'message' => 'I want to display this message on my wall'
));
Facebook 담벼락에 게시물 제출 :
fbConfig.php 파일을 포함하여 Facebook API를 연결하고 액세스 토큰을 얻습니다.
게시물 메시지, 이름, 링크, 설명 및 사진이 Facebook 담벼락에 제출됩니다. 게시물 제출 상태가 표시됩니다.
FB 액세스 토큰 ($ accessToken)을 사용할 수없는 경우 Facebook 로그인 URL이 생성되고 사용자는 FB 로그인 페이지로 리디렉션됩니다.
Facebook 벽에 게시 PHP SDK
<?php
//Include FB config file
require_once 'fbConfig.php';
if(isset($accessToken)){
if(isset($_SESSION['facebook_access_token'])){
$fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
}else{
// Put short-lived access token in session
$_SESSION['facebook_access_token'] = (string) $accessToken;
// OAuth 2.0 client handler helps to manage access tokens
$oAuth2Client = $fb->getOAuth2Client();
// Exchanges a short-lived access token for a long-lived one
$longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($_SESSION['facebook_access_token']);
$_SESSION['facebook_access_token'] = (string) $longLivedAccessToken;
// Set default access token to be used in script
$fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
}
//FB post content
$message = 'Test message from CodexWorld.com website';
$title = 'Post From Website';
$link = 'http://www.codexworld.com/';
$description = 'CodexWorld is a programming blog.';
$picture = 'http://www.codexworld.com/wp-content/uploads/2015/12/www-codexworld-com-programming-blog.png';
$attachment = array(
'message' => $message,
'name' => $title,
'link' => $link,
'description' => $description,
'picture'=>$picture,
);
try{
//Post to Facebook
$fb->post('/me/feed', $attachment, $accessToken);
//Display post submission status
echo 'The post was submitted successfully to Facebook timeline.';
}catch(FacebookResponseException $e){
echo 'Graph returned an error: ' . $e->getMessage();
exit;
}catch(FacebookSDKException $e){
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
}else{
//Get FB login URL
$fbLoginURL = $helper->getLoginUrl($redirectURL, $fbPermissions);
//Redirect to FB login
header("Location:".$fbLoginURL);
}
굴절 :
https://github.com/facebookarchive/facebook-php-sdk
https://developers.facebook.com/docs/pages/publishing/
https://developers.facebook.com/docs/php/gettingstarted
http://www.pontikis.net/blog/auto_post_on_facebook_with_php
https://www.codexworld.com/post-to-facebook-wall-from-website-php-sdk/