![](/img/trans.png)
[英]Forbidden error 403 in Unification Engine API while sending message
[英]403 forbidden error while sending messages to facebook connector through Unification Engine API
我正在使用統一引擎 #unificationengine API 在 facebook 上發布消息。 我遵循了所有步驟並創建了連接以使用連接器。 在發送消息之前,所有 curl 請求都可以正常工作。 在創建用戶的每個卷曲中,創建連接,連接刷新我得到
{'status':200,'info':'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 和信息:禁止響應。
我已經嘗試了文檔和堆棧溢出或任何其他網站中可用的所有內容。 但是運氣不好。
請建議我為什么會收到此錯誤?
參考問題:
謝謝。
更新我在 curl 請求中添加了這三個選項:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_VERBOSE, true);
現在我收到 498,無效的訪問令牌錯誤:
"{\\"Status\\":{\\"facebook\\":{\\"status\\":498,\\"info\\":\\"無效令牌:\\"}},\\"URIs\\":[] }
請按照 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);
}
訪問令牌可能已過期。 請重新連接 Facebook 連接或刷新連接。
facebook 訪問令牌的生命周期約為兩個小時。 對於壽命較長的網絡應用程序,尤其是服務器端,需要生成壽命較長的令牌。 長壽命代幣通常持續約 60 天。
UE 具有刷新 facebook 令牌的能力。 使用“apiv2.unificationengine.com/v2/connection/add”添加連接后; api 調用,那么你應該調用“apiv2.unificationengine.com/v2/connection/refresh”; api 使短期令牌成為長期存在。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.