我在使用最新的 Facebook PHP SDK 将图片上传到 Facebook 上的用户相册时遇到问题。我可以上传一张图片,但是在第一张之后,它不会让我上传第二张图片(我已经尝试过使用与第一张相同的图片以及完全不同的图片)。
我认为这不是身份验证问题,因为我能够上传第一张图片,并且在检查用户的身份验证内容后,我得到以下信息:
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] =>
)
任何帮助表示赞赏。
注意:我的应用程序仍处于沙盒阶段,我正在本地服务器上运行它。