Я пытаюсь создать страницу PHP, которая создаст фотоальбом и загрузит фотографию.Пока что он аутентифицирует и создает фотоальбом без каких-либо проблем, но я не могу получить его для загрузки фотографии.Я получаю следующую ошибку:
Предупреждение: fopen (https://graph.facebook.com/yyyyyyyyyyyyyyyyy/photos?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx) [function.fopen]: не удалось открыть поток: сбой HTTP-запроса! HTTP / 1.0 400 Bad Request в / home / content /30/8734730 / html / uploadPhoto.php в строке 96
<html>
<head>
<title>Photo Upload</title>
</head>
<body>
<?php
$app_id = "xxxxxxxxxxxxxxxx";
$app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$post_login_url = "http://xyz.com/uploadPhoto.php";
$album_name = "Brand Image Productions";
$album_description = "Blah Blah event Photos";
$photo_source = 'C:\Users\Public\Pictures\Sample Pictures\Lighthouse.jpg';
$photo_message = 'Here is the lighthouse';
$code = $_REQUEST["code"];
echo "code ==>" . $code . '<br/><br/>';
//Obtain the access_token with publish_stream permission
if(empty($code)){
$dialog_url= "http://www.facebook.com/dialog/oauth?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode($post_login_url)
. "&scope=publish_stream,user_photos";
echo("<script>top.location.href='" . $dialog_url .
"'</script>");
}
else {
$token_url= "https://graph.facebook.com/oauth/"
. "access_token?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode( $post_login_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$access_token = $params['access_token'];
echo "access_token ==>" . $access_token . '<br/><br/>';
// Create a new album
$graph_url = "https://graph.facebook.com/me/albums?"
. "access_token=". $access_token;
$postdata = http_build_query(
array(
'name' => $album_name,
'message' => $album_description
)
);
$opts = array('http' =>
array(
'method'=> 'POST',
'header'=> 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = json_decode(file_get_contents($graph_url, false, $context));
// Get the new album ID
$album_id = $result->id; //upload photo
echo "album_id ==>" . $album_id . '<br/><br/>';
// Upload the photo
$graph_url = "https://graph.facebook.com/" . $album_id . "/photos?access_token=" . $access_token;
echo "graph_url ==>" . $graph_url . '<br/><br/>';
echo "photo_message ==>" . $photo_message . '<br/>';
echo "photo_source ==>" . $photo_source . '<br/><br/>';
$postdata = http_build_query(
array(
'message' => $photo_message,
'source' => $photo_source
)
);
$opts = array('http' =>
array(
'method'=> 'POST',
'header'=> 'Content-type: application/x-www-form-urlencoded',
'enctype' => 'multipart/form-data',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$fp = fopen($graph_url, 'r', false, $context);
fpassthru($fp);
fclose($fp);
}
?>
</body>
</html>