gpt4 book ai didi

php - Facebook 页面墙自动发布图片调整大小

转载 作者:太空宇宙 更新时间:2023-11-04 10:39:02 27 4
gpt4 key购买 nike

我已成功创建代码,使用长期访问 token 将我的网站输入发布到 Facebook 页面。

使用的SDK:PHP SDK v5

问题

1) 尽管我共享绝对路径,但图片不显示。

2) 使用以下代码发布的图片区域,显示全宽。有没有办法像预期的结果图像那样调整大小。

enter image description here

我的代码

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;

}

预期结果(如果可能)

enter image description here

最佳答案

  1. 当我尝试访问您提供的图片 url 时,出现 404 错误:找不到图片。这就是未加载 is 的原因。
  2. 您想要的结果有点过时了。 Facebook wants the image至少为 200x200 像素,但图像越大(在特定纵横比下)越好:

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.

还要确保使用 og:image:widthog:image:height 让 Facebook 知道实际图像大小是多少。

提示:请使用Facebook debug tool尝试并纠正您的错误。

关于php - Facebook 页面墙自动发布图片调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35974548/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com