Bonjour,
j'essaye depuis ce matin de me connecter a l'API Facebook mais j'ai un problème, je me connecte bien mais il m'affiche I don't understand. Ask me 'hi'. en boucle, voici le code :
j'ai essayer de mettre une condition si le message est vide on ne fait rien mais du cou il ne répond pas non plus quand le message est envoyer comme ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 <?php // parameters $hubVerifyToken = 'xxx'; $accessToken = "xxx"; // check token at setup if ($_REQUEST['hub_verify_token'] === $hubVerifyToken) { echo $_REQUEST['hub_challenge']; exit; } // handle bot's anwser $input = json_decode(file_get_contents('php://input'), true); $senderId = $input['entry'][0]['messaging'][0]['sender']['id']; $messageText = $input['entry'][0]['messaging'][0]['message']['text']; $answer = "I don't understand. Ask me 'hi'."; if($messageText == "hi") { $answer = "Hello"; } $response = [ 'recipient' => [ 'id' => $senderId ], 'message' => [ 'text' => $answer ] ]; $ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$accessToken); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response)); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); curl_exec($ch); curl_close($ch); exit; ?>
if(!empty($messageText)){
...
}
Cordialement
Partager