波纹管代码工作正常。它上传照片并创建新照片。显然我不知道如何让它重定向到某个地方,最终得到一个带有专辑ID的空白页面。我想要一个重定向链接,在该重定向链接上应该显示照片。我希望在上传照片后重定向用户。当用户按下上传按钮时上传照片。
$post_login_url = "http://apps.facebook.com/firstestt/upload.processor.php";
$album_name = 'Facepic Album';
$album_description = 'http://apps.facebook.com/firstestt/';
$code = $_REQUEST["code"];
$facebook->setFileUploadSupport(true);
//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 = $facebook->getAccessToken();
// 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/>';
//When this button is pressed the page should upload the photo and redirect the user to another link
echo '<input type="submit" value="Upload" /><br/>';
echo '</form>';
echo '</body></html>';
}
答案 0 :(得分:0)
我认为this article完全符合您的需求。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>WebSpeaks.in | Upload images to Facebook</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
html{
font-family: "lucida grande",tahoma,verdana,arial,sans-serif;
}
.main{
width:400px;
margin:auto;
border:2px solid #0066CC;
color:#3B5998;
padding:20px;
font-size: 11px;
-moz-border-radius: 4px 4px 4px 4px;
border-radius: 4px 4px 4px 4px;
-moz-box-shadow: 1px 1px 0 #d5d5d5;
background: none repeat scroll 0 0 #F2F2F2;
}
.post_but {
background: none repeat scroll 0 0 #EEEEEE;
border-color: #999999 #999999 #888888;
border-style: solid;
border-width: 1px;
color: #333333;
cursor: pointer;
display: inline-block;
font-size: 11px;
font-weight: bold;
padding: 2px 6px;
text-align: center;
text-decoration: none;
}
a{
color:#3B5998;
}
</style>
</head>
<body>
<?php
/******************Configuration options***********************/
require_once 'library/facebook.php';
$facebook = new Facebook(array(
'appId' => $appId, //your facebook application id
'secret' => $secret, //your facebook secret code
'cookie' => true
));
$user = $facebook->getUser();
if(is_null($facebook->getUser()))
{
header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos'))}");
exit;
}
/******************Configuration options***********************/
if($_SERVER['REQUEST_METHOD'] =='POST'){
$img = realpath($_FILES["pic"]["tmp_name"]);
// allow uploads
$facebook->setFileUploadSupport("http://" . $_SERVER['SERVER_NAME']);
// add a status message
$photo = $facebook->api('/me/photos', 'POST',
array(
'source' => '@' . $img,
'message' => 'This photo was uploaded via www.WebSpeaks.in'
)
);
echo '<p><a target="_blank" href="http://www.facebook.com/photo.php?fbid='.$photo['id'].'">Click here to watch this photo on Facebook.</a></p>';
}
?>
<div class="main">
<p>Select a photo to upload on Facebook.</p>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<p>Select the image: <input type="file" name="pic" /></p>
<p><input class="post_but" type="submit" value="Upload to my album" /></p>
</form>
</div>
</body>
</html>