Facebook Publish Status graph api

In PHP, I am trying to post the status to our Facebook fans page using the api chart, even though following the instructions in facebook, the following code does not seem to update the status.

Here is the code:

$xPost['access_token'] = "{key}";
$xPost['message'] = "Posting a message test.";

$ch = curl_init('https://graph.facebook.com/{page_id}/feed'); 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $xPost); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);  
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); 
curl_setopt($ch, CURLOPT_CAINFO, NULL); 
curl_setopt($ch, CURLOPT_CAPATH, NULL); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 

$result = curl_exec($ch); 

Does anyone know why this code is not working? Access_token rule

+3
source share
3 answers
    $url = "https://graph.facebook.com/ID_HERE/feed";
    $ch = curl_init();
    $attachment =  array(   'access_token'  => 'your token',                        
                        'name'          => "Title",
                        'link'          => "www.google.com",
                        'description'   => 'description here',
                    );

    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
    $result= curl_exec($ch);

    curl_close ($ch);
+3
source

it seems that "CURLOPT_SSL_VERIFYPEER" should be set to 0;

e.g. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
0
source

, () , :

    $url = "https://graph.facebook.com/" . $this->getPageId() . "/photos";
    $attachment = array(
        'access_token' => $this->getAccessToken(),
        'source' => '@' . $source,
        'aid' => $aid,
        'message' => $message,
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
    ob_start();
    curl_exec($ch);
    $this->setjsonResult(ob_get_contents());
    ob_end_clean();
    curl_close($ch);
0
source

Source: https://habr.com/ru/post/1745822/