我一直在寻找 4 小时的答案,但仍然无法解决。
Curl error: couldn't connect to host
是我得到的错误...他们说这可能是 SSL 问题...
我正在使用000webhost
,你可以在这里检查测试:http ://www.feriajanos.com/src/teszt.php
请帮我!
这是我使用的代码:
<?php
function curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $url );
$response = curl_exec($ch);
if($response === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
$response = $response;
}
curl_close($ch);
return $response;
}
$app_id = "MY_APP_ID";//do not show this
$app_secret = "MY_APP_SECRET";//do not show this
$fanpage_id ='MY_FANPAGE_ID';//do not show this
//Take NOTE: this must include http://
//ex. http://sharefavoritebibleverses.com/fb_connect.php
$post_login_url = "http://www.feriajanos.com/teszt.php";
//Take NOTE: this must include http://
$photo_url = "http://www.feriajanos.com/kepek/mas/posztok/poszt20130412104817.jpg";
//you can add link to your image caption, but you can't use this tag <a href='http://link.com' >visit my link</a>
$photo_caption = "Feri A János";
$code = $_REQUEST["code"];
//Obtain the access_token with publish_stream permission
if (!$code)
{
$dialog_url= "https://www.facebook.com/dialog/oauth?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode( $post_login_url)
. "&scope=publish_stream,manage_pages";
echo("<script>top.location.href='" . $dialog_url
. "'</script>");
}
if(isset($_REQUEST['code'] ))
{
$token_url="https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $app_id
. "&client_secret=" . $app_secret
. "&redirect_uri=" . urlencode( $post_login_url)
. "&code=" . $code;
$response = curl($token_url);
$params = null;
parse_str($response, $params);
$access_token = $params['access_token'];
// POST to Graph API endpoint to upload photos
$graph_url= "https://graph.facebook.com/me/photos?"
. "url=" . urlencode($photo_url)
. "&message=" . urlencode($photo_caption)
. "&method=POST"
. "&access_token=" .$access_token;
echo '<html><body>';
echo curl($graph_url);
echo '</body></html>';
}
?>