我在这里为我的Facebook应用程序使用这个脚本。
它会在用户的 Facebook 个人资料中上传照片,并为该照片创建一个新相册。
该脚本返回"[应用程序名称]照片"作为相册名称/标题(不带引号)。
- [应用程序名称]是我的Facebook应用程序的名称 -
基本上,我不想要那个专辑标题。我想在脚本上指定专辑标题。
我想要的是:
- 。以便能够从脚本中指定要创建的相册的名称/标题。
- 如果可能,也指定专辑描述。
这是剧本——
$root_url = "http://www.WEBSITE.COM/";
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
// Get image from URL
$img = $_GET['i'];
// Change location depending on which type of cover
if($get_set != 1) {
$photo = './PATH/'.$img.''; // Path to the photo on the local filesystem
} else {
$photo = './PATH/'.$img.'';
}
$message = 'THIS IS THE PHOTO CAPTION';
if($user_id) {
// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {
// Upload to a user's profile. The photo will be in the
// first album in the profile. You can also upload to
// a specific album by using /ALBUM_ID as the path
$ret_obj = $facebook->api('/me/photos', 'POST', array(
'source' => '@' . $photo,
'message' => $message,
)
);
// echo '<pre>Photo ID: ' . $ret_obj['id'] . '</pre>';
print "<script>window.location = '".$root_url."index.php?cover=uploaded'</script>";
} catch(FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $facebook->getLoginUrl( array(
'scope' => 'photo_upload'
));
echo '<script> window.location = "' . $login_url . '"; </script>';
error_log($e->getType());
error_log($e->getMessage());
}
echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';
} else {
// No user, print a link for the user to login
// To upload a photo to a user's wall, we need photo_upload permission
// We'll use the current URL as the redirect_uri, so we don't
// need to specify it here.
$login_url = $facebook->getLoginUrl( array( 'scope' => 'photo_upload') );
echo '<script> window.location = "' . $login_url . '"; </script>';
//echo 'Please <a href="' . $login_url . '">login</a> to continue.';
}
在这里看到这个,我相信这是可能的。
$album_name = 'YOUR_ALBUM_NAME';
$album_description = 'YOUR_ALBUM_DESCRIPTION';
我只是不知道如何在那里工作...
期待解决方案。谢谢你的时间!
正如它在 Photo 对象的文档中所说:
您您可以通过向照片发出 HTTP POST 请求来上传照片 内容和图形 API 的可选说明之一 连接:
https://graph.facebook.com/USER_ID/photos - 照片将发布到为应用创建的相册。我们会自动创建一个 应用的相册(如果尚不存在)。所有照片已上传 然后,这种方式将添加到同一相册中。
https://graph.facebook.com/ALBUM_ID/photos - 照片将发布到特定的现有相册,由 ALBUM_ID. 普通相册的大小限制为 200 张照片。违约 应用程序相册的大小限制为 1000 张照片。
当前正在使用第一个选项,使用第二个选项需要您有一个专辑 ID,您首先需要创建该 ID:
您可以通过向用户发出 HTTP POST 请求来为用户创建相册 PROFILE_ID具有publish_stream权限和 以下参数
(用户对象的相册连接)
问题是,您必须保存此相册 ID,以便用户将来在应用需要再次上传到相册时使用。