强制 Facebook 帖子的图像大小

问题描述 投票:0回答:1

我正在使用 PHP Graph SDK 在 Facebook 上发布带有图像的帖子,源图像大小为 900x900px。

这是我的代码总结:

require_once('php-graph-sdk-5.x/src/Facebook/autoload.php');

$fbk_appid = 'xxxx';
$fbk_appsecret = 'xxxx';
$fbk_tokenpage = 'xxxx';
$fbk_pageid = 'xxxx';       

$picture = 'img1.jpg';
$link = 'https://www.mysite.ext/page.html';
$message = 'My message';            
$name = 'Title under image'; 
$tags = '#tags...';
$description = 'Description under title';                               

$fb = new Facebook\Facebook([
    'app_id' => $fbk_appid,
    'app_secret' => $fbk_appsecret,
    'default_graph_version' => 'v3.3'
    ]);
    
try{
    $response = $fb->post('/'.$fbk_pageid.'/feed',
            array (
                'picture' => $picture,
                'link' => $link,
                'message' => $message,          
                'name' => $name,
                'description' => $description,          
            ),
            $fbk_tokenpage
    );
}catch(Facebook\Exceptions\FacebookResponseException $e){
    // Error Graph ( $e->getMessage() )         
}catch(Facebook\Exceptions\FacebookSDKException $e){
    // Error SDK ( $e->getMessage() )           
}
    
// $response->getGraphNode(); //e.g. {"id":"1446491425007649_523376413379549"}

发布后,图像大小始终调整为 1200x628px。 如何强制自定义图像格式(例如方形)?

谢谢!

image facebook post resize feed
1个回答
0
投票

我解决了! 我使用 /photo 而不是 /feed,如下所示:

$response = $fb->post('/'.$fbk_pageid.'/photos',                    
                array (
                    'message' => 'Head text', 
                    'source' => $fb->fileToUpload('https://www.mysite.ext/img.png')
                ),                  
                $fbk_tokenpage
            );  
© www.soinside.com 2019 - 2024. All rights reserved.