我正在使用统一引擎#unificationengine在facebook上发布消息。我按照所有步骤创建了连接以使用连接器。在发送消息之前,所有的卷曲请求都正常工作。在创建用户的每一个卷曲中,创建连接,刷新连接。
{“状态”:200,“信息”:“ok”}
现在,我想使用连接器在facebook上发布消息。下面是我的卷曲代码:
$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];我得到的是:
状态: 403和信息:禁止回应。
我已经尝试了所有可用的文档和堆栈溢出或任何其他网站。但运气不好。
请告诉我为什么会有这个错误?
参考:所以问题:
谢谢。
Update I在curl请求中添加了这三个选项:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_VERBOSE, true); 现在我得到了498,无效的访问令牌错误:
“{\”状态\“:{\”facebook\“:{\”status\“:498,\”info\“:\”无效令牌:\“},\"URIs\":[] }
发布于 2017-08-01 06:16:31
请按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);
}发布于 2017-01-07 09:29:58
访问令牌可能已经过期。请重新连接facebook连接或刷新连接。
facebook访问令牌的生命周期约为两个小时。对于更长寿的web应用程序,特别是服务器端,需要生成长寿命的令牌。长寿的代币一般持续60天左右。
UE具有刷新facebook令牌的能力。在使用"apiv2.unificationengine.com/v2/connection/add";api调用添加连接之后,您应该调用"apiv2.unificationengine.com/v2/connection/refresh";api来使短寿命令牌变为长寿命令牌。
https://stackoverflow.com/questions/41502783
复制相似问题