필요 I가 내가 작업에 매우 근접하다고 생각하지만, 나는 다음과 같은 오류가 계속 다음 코드를게시 사진 업로드 파일 오류
는{"error":{"message":"(#324) Requires upload file","type":"OAuthException"}}
하지만 난을 지정하는 방법을 알아낼 수 없습니다 파일 업로드 ... 나는 이미지와 소스를 모두 시도했는데 둘 다 같은 오류가 발생합니다.
<html>
<head>
<title>Photo Upload</title>
</head>
<body>
<?php
$app_id = "MY APP ID GOES HERE";
$app_secret = "MY APP SECRET GOES HERE";
$post_login_url = "MY URL GOES HERE";
$album_name = "Test Album";
$album_description = "Blah Blah event Photos";
$photo_source = realpath("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
$args = array('message' => $photo_message,
'image' => $photo_source
);
$ch = curl_init();
$url = 'https://graph.facebook.com/'.$album_id.'/photos?
access_token='.$access_token;
echo "url ==>" . $url . '<br/><br/>';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$data = curl_exec($ch);
echo "data ==>" . $data . "<br>";
}
?>
</body>
</html>
저는 약간 혼란 스럽습니다. @가 에러 메시지를 억제한다는 것을 알았습니다. 나는 내 코드를 변경 : 인라인'$ 인수 = 배열 ('메시지'=> $의 photo_message, '이미지'=> 파일 ($의 photo_source) ) ' 지금은 내 파일이 존재 나던 것을 불평 서버에. 나는 서버 파일을 원하지 않는다. 로컬 파일을 원한다. 나는 무엇이 없는가 ?? – Jesse57
그래, 내 대답을 찾은 것 같아. 그들이 fopen이 로컬 파일을 열 것이라고 말하면 스크립트가 실행되고있는 곳, 내 경우에는 아빠가있는 서버를 의미합니다. 나는 이것이 보안상의 이유라고 추측하고있다. 다른 이유는 없다. 누군가 나를 위해 이것을 확인할 수 있습니까? 나는 이것이 올바른 것이라면 다른 각도에서 접근해야한다고 생각합니다. – Jesse57
@JesseCreamer 로컬 파일과 서버 중 하나를 서버에 먼저 업로드해야하는 경우 필요합니다. 그리고 예. 일반적으로 동일한 서버에있는 파일을 업로드하여 업로드합니다. 실제로는 보안상의 이유로뿐만 아니라 복잡한 흐름이 많이 발생합니다.이 문제는 또 하나의 질문입니다. –