사진을 사용자 프로필에 업로드하려고하는 중입니다./me/photos에 게시하여 기본 앱 앨범에 사진을 업로드 할 수있었습니다. 그러나 같은 방법으로 같은 앨범에 다른 사진을 올리려고하면 OAuthException을 반환합니다. 별도의 기존 앨범에 업로드하려고 할 때도 똑같은 일이 발생합니다.기존 앨범에 사진 업로드
앱 앨범을 삭제하면 다시 업로드 할 수 있지만 작동하지만 다른 앨범을 업로드하려고하면 실패합니다.
저는 .NET SDK와 표준 PHP SDK를 모두 사용해 보았습니다. 둘 다 같은 결과를냅니다.
여기
내가 내 양식을 작업 게시하도록하겠습니다된다 .NET의 SDK 코드 :
public ActionResult UploadToDefaultAlbum(PhotoUploadModel model)
{
model = model ?? new PhotoUploadModel();
if (model.IsPostback)
{
if (model.PhotoUpload != null)
{
var fb = new FacebookWebClient(model.AccessToken);
dynamic parameters = new ExpandoObject();
parameters.title = model.Title;
parameters.description = model.Title + " description";
parameters.source =
new FacebookMediaObject {ContentType = model.PhotoUpload.ContentType, FileName = model.PhotoUpload.FileName}.
SetValue(GetFileBytes(model.PhotoUpload.InputStream));
var result = fb.Post("/me/photos", parameters);
ViewBag.Message = result;
}
else
{
ViewBag.Message = "PhotoUpload is null";
}
}
model.IsPostback = true;
return View("Upload",model);
}
그리고 내 HTML 양식 :
@using (Html.BeginForm("UploadToDefaultAlbum", "Photos", FormMethod.Post, new { enctype = "multipart/form-data"})) {
<fieldset>
<legend>Upload to default App album</legend>
<div class="editor-label">
@Html.LabelFor(m => m.Title)
</div>
<div class="editor-field">
@Html.InputFor(System.Web.Mvc.Html5.InputType.Text, x => x.Title)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.PhotoUpload)
</div>
<div class="editor-field">
@Html.InputFor(System.Web.Mvc.Html5.InputType.File, x => x.PhotoUpload)
</div>
@Html.HiddenFor(x => x.IsPostback)
@Html.HiddenFor(x => x.AccessToken)
<button type="submit">Submit</button>
</fieldset>
}
사용자가 양식 페이지를로드하면 user_photos 및 p가 있는지 확인합니다. ublish_stream 권한 (CanvasAuthorize 속성 사용).
기존 앨범에 업로드 할 수 있도록 누락 된 항목이 있습니까?
PHP의 SDK 코드
나는 https://developers.facebook.com/blog/post/498/에서 직접이 코드를 복사하여 내 응용 프로그램의 상단에있는 변수를 설정합니다. ?<?php
$app_id = "xxx";
$app_secret = "xxx";
$post_login_url = "https://localhost/facebookresearch/photoupload.php";
$album_name = 'PHP Test Album';
$album_description = 'YOUR_ALBUM_DESCRIPTION';
$code = $_REQUEST["code"];
//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";
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'];
// 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;
//Show photo upload form and post to the Graph URL
$graph_url = "https://graph.facebook.com/". $album_id
. "/photos?access_token=" . $access_token;
echo '<html><body>';
echo '<form enctype="multipart/form-data" action="'
.$graph_url. ' "method="POST">';
echo 'Adding photo to album: ' . $album_name .'<br/><br/>';
echo 'Please choose a photo: ';
echo '<input name="source" type="file"><br/><br/>';
echo 'Say something about this photo: ';
echo '<input name="message" type="text"
value=""><br/><br/>';
echo '<input type="submit" value="Upload" /><br/>';
echo '</form>';
echo '</body></html>';
}
>
응답은 다음과 같습니다
{
"error": {
"message": "An unexpected error has occurred. Please retry your request later.",
"type": "OAuthException"
}
}
그것은 앨범을 만들지 만에 사진을 업로드 할 수 없습니다. 그래서 내 앱이나 FB에서 버그가있는 설정이있는 것 같습니다. 나는 전자를 추측 하겠지만, 그것이 무엇인지 알 수는 없다.
앱이 샌드 박스 모드이고 테스트 사용자를 사용하고 있다는 점이 차이가 있습니까?
두 번째 사진을/me/photos/사진의 사진 앨범에 업로드하려고하면 왜 동일한 오류가 발생합니까? – jwynveen