PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 11, 2022

[FIXED] Facebook PHP SDK - Getting error when posting to facebook page but post is created

 February 11, 2022     facebook-php-sdk, php     No comments   

Issue

I don't know why but I get the following error when I'm trying to post to a facebook page that I've created:

Fatal error: Uncaught exception 'Facebook\FacebookAuthorizationException' with message 'Unsupported post request.

Here's the code that I currently have:

<?php
session_start();

require 'vendor/autoload.php';


use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\GraphUser;


FacebookSession::setDefaultApplication('my-app-id', 'my-app-secret');

$session = new FacebookSession('my-access-token');

if($session){

    $request = new FacebookRequest($session, 'GET', '/me/accounts?fields=name,access_token,perms');
    $pageList = $request->execute()->getGraphObject()->asArray();
    $token = $pageList['data'][0]->access_token;

    $request2 = new FacebookRequest(
        $session,
        'POST',
        '/my-page-id/feed',
        array (
          'access_token' => $token,
          'name' => 'MySQL: Why My?',
          'caption' => 'MySQL: Why My?',
          'link' => 'http://www.vertabelo.com/blog/mysql-history',
          'message' => 'MySQL: Why My?',
        )
    );

    $response2 = $request2->execute();
    print_r($response2);

}

An error is returned but the post is actually posted in the facebook page when I check. Am I doing something wrong here?

Another alternative that I tried is to get the page access token from another page load and then set it on the new FacebookSession call instead of the access token of my profile. Then I omit the access_token in the request for creating a new post. It also returns an error but the post is also created on the page. Any ideas?


Solution

This is specifically related to POSTing the link field to the /{page-id}/feed endpoint.

This error is returned when your app is in development mode. If you make the app live, it should work.

Pretty sure this is not the intended behavior, so I submitted a bug report.



Answered By - SammyK
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing