最新のFacebookPHPSDKを使用してFacebookのユーザーアルバムに写真をアップロードする際に問題が発生しました。1枚の画像をアップロードできますが、最初の画像の後に2番目の画像をアップロードできません(最初の画像と同じ画像とまったく異なる画像を使用してこれを試しました)。
最初の画像をアップロードできるので、認証の問題ではないと思います。ユーザーが何に対して認証されているかを確認した後、次のようになります。
Array (
[data] => Array (
[0] => Array (
[installed] => 1
[status_update] => 1
[photo_upload] => 1
[video_upload] => 1
[email] => 1
[create_note] => 1
[share_item] => 1
[publish_stream] => 1
[publish_actions] => 1
[user_likes] => 1
[user_photos] => 1
)
)
)
画像のアップロードに現在使用しているコードは次のとおりです。
<?php
$mee = $facebook->api('/me');
//echo $mee['name']; // test to make sure FB is connected
$item = '202';
$filename = 'bc2a846f1bfafa8d811390089a91bcfa.jpeg';
$qry = "SELECT albumID FROM os_users WHERE user_fbid = '".$_SESSION['fbid']."'";
$result = mysql_query($qry);
$alb = mysql_fetch_assoc($result);
// Check if Album already exists
if($alb['albumID'] != '0'){
$album_id = $alb['albumID'];
} else {
echo 'Creating Album';
//Create an album
$album_details = array(
'message' => 'Album Message',
'name' => 'Album Name'
);
$create_album = $facebook->api('/me/albums', 'post', $album_details);
// Get album ID of the album you've just created
$album_id = $create_album['id'];
$qry = "UPDATE scav_users SET user_albumid = '".$album_id."' WHERE user_fbid = '".$_SESSION['ufbid']."'";
$result = mysql_query($qry);
}
// Upload Image
$facebook->setFileUploadSupport(true);
$photo_details = array(
'message' => '#'.$item.': Item Description'
);
$photo_details['image'] = '@' . realpath('../uploads/'.$filename);
try {
$upload_photo = $facebook->api('/'.$album_id.'/photos', 'post', $photo_details);
} catch (FacebookApiException $e){print_r($e);}
//$upload_photo = $facebook->api('/me/photos', 'post', $photo_details);
$photo_id = $upload_photo['id'];
echo $photo_id;
?>
別の画像をアップロードしようとした後のこのスクリプトの結果であるエラーは次のとおりです。
FacebookApiException Object (
[result:protected] => Array (
[error] => Array (
[message] => An unexpected error has occurred. Please retry your request later.
[type] => OAuthException
[code] => 2
)
)
[message:protected] => An unexpected error has occurred. Please retry your request later.
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => [locationtofile]base_facebook.php
[line:protected] => 1106
[trace:Exception:private] => Array (
[0] => Array (
[file] => [locationtofile][base_facebook.php
[line] => 810
[function] => throwAPIException
[class] => BaseFacebook
[type] => ->
[args] => Array (
[0] => Array (
[error] => Array (
[message] => An unexpected error has occurred. Please retry your request later.
[type] => OAuthException
[code] => 2
)
)
)
)
[1] => Array (
[function] => _graph
[class] => BaseFacebook
[type] => ->
[args] => Array (
[0] => //photos
[1] => post
[2] => Array (
[message] => #202: Item Description
[image] => @[locationtofile]bc2a846f1bfafa8d811390089a91bcfa.jpeg
)
)
)
[2] => Array (
[file] => [locationtofile][base_facebook.php
[line] => 587
[function] => call_user_func_array
[args] => Array (
[0] => Array (
[0] => Facebook Object (
[appId:protected] => 435146213185130
[appSecret:protected] => 96797309425855946b0b495f9adf6252
[user:protected] =>
[signedRequest:protected] => Array (
[algorithm] => HMAC-SHA256
[code] => 2.AQBPPU0myCWfUCPt.3600.1342501200.1-100003953568312|8LHGtxCV0OZZfE-826am15ODSZo
[issued_at] => 1342495041
[user_id] => 100003953568312
)
[state:protected] =>
[accessToken:protected] => AAAGLw192VmoBABK5rNEsnoROQHvcFuKt720JuUV2DP20llDD1Ny9NPLE2ZBVi4WIypB5n1yfodv7VBWFTrTi0dF6Ncm3PGIxDK2yCmbJPJO14xH7C
[fileUploadSupport:protected] => 1
)
[1] => _graph
)
[1] => Array (
[0] => //photos
[1] => post
[2] => Array (
[message] => #202: Item Description
[image] => @[locationtofile]bc2a846f1bfafa8d811390089a91bcfa.jpeg
)
)
)
)
[3] => Array (
[file] => [locationtofile][uploadtoFB.php
[line] => 44
[function] => api
[class] => BaseFacebook
[type] => ->
[args] => Array (
[0] => //photos
[1] => post
[2] => Array (
[message] => #202: Item Description
[image] => @[locationtofile]bc2a846f1bfafa8d811390089a91bcfa.jpeg
)
)
)
)
[previous:Exception:private] =>
)
どんな助けでも大歓迎です。
注:私のアプリケーションはまだサンドボックスの段階にあり、ローカルサーバーで実行しています。