Reputation: 331
I have successfully created code for posting my website inputs to Facebook page using long lived access token.
SDK used: PHP SDK v5
Problem
1) Picture not displaying despite I am sharing absolute path.
2) Picture area posted using following code, showing full width. Is there any way to resize like expected result image.
My code
if(!isset($_SESSION)){session_start();}
require_once 'facebook-sdk-v5/autoload.php';
//facebook page id
$pageId = 'XXXXXXXXXXXXXX';
$fb = new Facebook\Facebook([
'app_id' => 'XXXXXXXXXXXXXX',
'app_secret' => 'XXXXXXXXXXXXXX',
'default_graph_version' => 'v2.5',
]);
//LONG LIVED ACCESS TOKEN (60 DAYS)
$token = 'XXXXXXXXXXXXXXXXXXXXXX';
if (isset($token))
{
$client = $fb->getOAuth2Client();
try
{
$accessToken = $client->getLongLivedAccessToken($token);
}
catch(Facebook\Exceptions\FacebookSDKException $e)
{
echo $e->getMessage();
exit;
}
$response = $fb->get('/me/accounts', (string) $token);
foreach ($response->getDecodedBody() as $allPages)
{
foreach ($allPages as $page )
{
if (isset($page['id']) && $page['id'] == $pageId)
{ // Suppose you save it as this variable
$appAccessToken = (string) $page['access_token'];
break;
}
}
}
$response = $fb->post(
'/'.$pageId.'/feed',
array(
"message" => "http://www.aazabc.com/30",
"link" => "http://www.aazabc.com/30",
"picture" => "http://www.aazabc.com/images/jobs.jpg",
"name" => "UK SHIFT INBOUND CUSTOMER SERVICE / BOTH SIDE CABS",
"caption" => "www.aazabc.com",
"description" => "Hiring For UK Telecom Customer Service Process Inbound Customer Service UG / Grad / Dropout CAN Apply Freshers Can Apply 5 Days Working Location Gurgaon International Training Facility Both Side Cab Salary 20K - 25K + Incentives (8K-10K)"
),
$appAccessToken
);
// Success
$postId = $response->getGraphNode();
// echo $postId;
}
Expected result (if possible)
Upvotes: 0
Views: 177
Reputation: 8069
Use images that are at least 1200 x 630 pixels for the best display on high resolution devices. At the minimum, you should use images that are 600 x 315 pixels to display link page posts with larger images. Images can be up to 8MB in size.
Also make sure to use og:image:width
and og:image:height
to let Facebook already know what the actual image size is.
Tip: Please use the Facebook debug tool to try and correct your errors.
Upvotes: 1