Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
facebook API的问题_Facebook_Facebook Graph Api - Fatal编程技术网

facebook API的问题

facebook API的问题,facebook,facebook-graph-api,Facebook,Facebook Graph Api,我有一个facebook应用程序的问题,当我试图发送一条消息来接收机器人时,我得到了这个错误。 如果您需要php脚本来更好地理解错误,只需询问 <html><head> <title>301 Moved Permanently</title> </head><body> <h1>Moved Permanently</h1> <p>The document has moved <a h

我有一个facebook应用程序的问题,当我试图发送一条消息来接收机器人时,我得到了这个错误。 如果您需要php脚本来更好地理解错误,只需询问

<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://4eecef78.ngrok.io/whatsapp/">here</a>.</p>
</body></html>

301永久搬迁
永久移除
文档已移动

这是我的index.php脚本

<?php
$access_token = "EAANXQoEiXdsBAAeeSGCv80gkk8tzo4hHYUMbfW3xCu8en9QjaLrDpT2Pj2ChO9668stns6xNao5NGyNKldw5v9yXUCnc1qvHSCuZCvhChoP59uiMZC9k27lMSRAD2ZB0qro5ABrptXHHZACHs3cDLlNggVBMLwrqWCgSjKz8lQZDZD";
$verify_token = "fb";
$hub_verify_token = null;
 //verifica del token con fb per avere accesso all'app
if(isset($_REQUEST['hub_challenge'])) {
    $challenge = $_REQUEST['hub_challenge'];
    $hub_verify_token = $_REQUEST['hub_verify_token'];
}


if ($hub_verify_token === $verify_token) {
    echo $challenge;
}

$input = json_decode(file_get_contents('php://input'), true); //converto json in arrivo in array php

$sender = $input['entry'][0]['messaging'][0]['sender']['id']; //prendo id sender
$message = $input['entry'][0]['messaging'][0]['message']['text']; //prendo testo


 $message_to_reply = 'Huh! what do you mean?';
 //messaggio di bot
//da qui in poi si può fare una funzione di send message 
//
//API Url
$url = 'https://graph.facebook.com/v2.6/me/messages?access_token='.$access_token;
//formatto la risposta per fb mettendo id di ricezione e messaggio di risposta
$response= [
    'recipient' => [ 'id' => $sender ],
    'message' => [ 'text' => $message_to_reply]
];

$ch = curl_init($url); //inizializzo curl per fare la post


$jsonDataEncoded = json_encode($response); //traduco la response in json

//indico al curl che sarà una post
curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded); //appendo la risposta
//setto content type e variabili di sicurezza che non avendo tunnel ssl vanno settate cosi 
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
//curl_setopt($ch, CURLOPT_TIMEOUT, 100);
//invio il curl finchè arriva in 'posta un messaggio'
if(!empty($input['entry'][0]['messaging'][0]['message'])){
    $result = curl_exec($ch);

   //print var_dump($response);//stampo in console il testo di risposta da parte di fb per verifica
}



?>

问题解决了,我使用的是php开发服务器而不是web服务器。大错特错了,但最后我得到了

没有代码,我们无法帮助添加php脚本的代码