facebookarchive / php-graph-sdk

The Facebook SDK for PHP provides a native interface to the Graph API and Facebook Login. https://developers.facebook.com/docs/php
Other
3.17k stars 1.95k forks source link

Facebook SDK Post To facebook Page( image ,thumbnail ) not working #1153

Open rigalpatel001 opened 4 years ago

rigalpatel001 commented 4 years ago

am trying to post on Facebook page using PHP facebook SDK. post with link and message is working fine but "Images, thumnail " not working getting below error.

" Uncaught Facebook\Exceptions\FacebookAuthenticationException: (#100) Only owners of the URL have the ability to specify the picture, name, thumbnail or description params"

I have added app domain and select website platform and add URL.

I have also done domain verification .

require_once(__DIR__.'/src/Facebook/autoload.php');
$appId = '###########';
$appSecret = '##############';
$pageId = '##########';
$userAccessToken = '###########';

$fb =  new \Facebook\Facebook([
    'app_id' => $appId,
    'app_secret' => $appSecret,
    'default_graph_version' => 'v2.5'
]);

$longLivedToken = $fb->getOAuth2Client()->getLongLivedAccessToken($userAccessToken);

$fb->setDefaultAccessToken($longLivedToken);

$response = $fb->sendRequest('GET', $pageId, ['fields' => 'access_token'])->getDecodedBody();

$foreverPageAccessToken = $response['access_token'];

$fb->setDefaultAccessToken($foreverPageAccessToken);

$postmovie = $fb->sendRequest('POST', "$pageId/feed", [
    'message' => 'I Like French Fries.',
    'link' => 'http://www.google.com'
]);

Above code is working fine new post is created on Facebook page.but when I add picture and thumnail in parameter its not working.

//FB post content
 $message = 'Test message from Mr video website';
 $title = 'Latest Relased Movie';
 $link = 'http://google.com';
 $description = 'Movie Name: Saaho';
 $picture = 'http://google.com/images/test.jpg';

 $attachment = array(
     'message' => $message,
     'name' => $title,
     'link' => $link,
     'description' => $description,
     'picture'=>$picture,
 );

$fb->setDefaultAccessToken($foreverPageAccessToken);
$postmovie = $fb->sendRequest('POST', "$pageId/feed",$attachment);

Anyone please suggest possible solution to fix these issue?

Thanks

itajackass commented 4 years ago

Same problem for me. Some update?

bullride commented 4 years ago

Hi @rigalpatel001

All you have to do is to chance the last line in the code you supplied. To post photos you need to remove feed & replace it with photos

$postmovie = $fb->sendRequest('POST', "$pageId/photos",$attachment);

Hope this help!