I am using unification engine #unificationengine API to post message on facebook. I followed all the steps and created connections to use connectors. All the curl requests are working fine till send message. In every curl from create user, create connection, connection refresh I am getting
{‘status’:200,’info’:’ok’}
And now I want to use the connector to post message on facebook. Below is my Curl code:
$post_msg = json_encode( array( 'message' => array( 'receivers' => array( array( 'name' => 'Me', 'address' =>'https://graph.facebook.com/'.$request->profile_id.'/feed?access_token='.$request->access_token.'&message=Hello&method=post', 'Connector' => 'facebook' ), ), 'sender' => array('address' => 'sender address'), 'subject' => 'Hello', 'parts' => array( array( 'id' => '1', 'contentType' => 'binary', 'data' => 'Hi welcome to UE', 'size' => 100, 'type' => 'body', 'sort' => 0 ), ), ), ) ); $ch = curl_init('https://apiv2.unificationengine.com/v2/message/send'); curl_setopt($ch, CURLOPT_USERPWD, "0a7f4444-ae4445-45444-449-d9b7daa63984:8755b446-6726-444-b34545d-713643437560"); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_msg); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // execute! $response = curl_exec($ch); // close the connection, release resources used curl_close($ch); // do anything you want with your response var_dump($response); return ['label' => $response];
and I am getting:
status: 403 and info: forbidden in response.
I have tried everything available in documentation and on stack overflow or any other website. But hard luck.
Please suggest why I am getting this error?
Refrence SO Questions:
Thanks.
Update I added these three options in curl request:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_VERBOSE, true);
and now I am getting 498, invalid access token error:
“{“Status”:{“facebook”:{“status”:498,”info”:”Invalid Token: “}},”URIs”:[] }
Advertisement
Answer
please use this as per php
public function facebookSharing($access_token) { $app = new UEApp(env('UNIFICATION_APP_KEY'), env('UNIFICATION_APP_SECRATE')); $user = new UEUser('unification_userkey', 'unification_usersecret'); $connection = $user->add_connection('FACEBOOK', "facebook", $access_token); $options = array( "receivers" => array( array( "name"=> "Me" ) ), "message"=>array( "subject"=>'testing', "body"=> 'description', "image"=> 'use any image url', "link"=>array( "uri"=> 'any web site url', "description"=> "", "title"=>"Title" ) ) ); $uris = $connection->send_message($options); }