Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Facebook上上传照片并创建相册。下载后,将用户重定向到另一个显示照片的页面_Php_Facebook_Photo - Fatal编程技术网

Php 在Facebook上上传照片并创建相册。下载后,将用户重定向到另一个显示照片的页面

Php 在Facebook上上传照片并创建相册。下载后,将用户重定向到另一个显示照片的页面,php,facebook,photo,Php,Facebook,Photo,下面的代码运行良好。它上载一张照片并创建一张新照片。显然,我不知道如何使它重定向到某个地方,它最终会出现一个带有相册id的空白页。我想放一个重定向链接,并在该重定向链接上显示照片。我想用户被重定向后,照片上传。当用户按下上载按钮时,将上载照片 $post_login_url = "http://apps.facebook.com/firstestt/upload.processor.php"; $album_name = 'Facepic Album'; $album_descri

下面的代码运行良好。它上载一张照片并创建一张新照片。显然,我不知道如何使它重定向到某个地方,它最终会出现一个带有相册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>';
  }
$post\u login\u url=”http://apps.facebook.com/firstestt/upload.processor.php";
$album_name='Facepic album';
$album\u description='1http://apps.facebook.com/firstestt/';
$code=$_请求[“code”];
$facebook->setFileUploadSupport(true);
//获取具有发布\u流权限的访问\u令牌
if(空($code))
{
$dialog_url=”http://www.facebook.com/dialog/oauth?"
“客户_id=”.$app_id
.“&redirect_uri=“.urlencode($post_login_url)
.“&scope=publish\u stream”;
echo(“top.location.href=”。$dialog\u url。
"'");
} 
否则{
$token_url=”https://graph.facebook.com/oauth/"
“访问令牌?”
“客户_id=”.$app_id
.“&redirect_uri=“.urlencode($post_login_url)
.“&client_secret=”.$app_secret
.“&code=”.$code;
$response=file\u get\u contents($token\u url);
$params=null;
parse_str($response,$params);
$access_token=$facebook->getAccessToken();
//创建新相册
$graph_url=”https://graph.facebook.com/me/albums?"
“access_token=”.$access_token;
$postdata=http\u构建\u查询(
排列(
'name'=>$album\u name,
'消息'=>$album\u说明
)
);
$opts=array('http'=>
排列(
'方法'=>'发布',
'标题'=>
'内容类型:application/x-www-form-urlencoded',
“内容”=>$postdata
)
);
$context=stream\u context\u create($opts);
$result=json\u decode(文件\u获取\u内容($graph\u url,false,
美元);;
//获取新相册ID
$album_id=$result->id;
//显示照片上传表单并发布到图形URL
$graph_url=”https://graph.facebook.com/“$album\u id
.“/photos?access_token=“.$access_token;
回声';
回声';
echo“将照片添加到相册:”.$album_name.

; echo“请选择一张照片:”; 回音“

”; echo“说说这张照片吧:”; 回音“

”; //当按下此按钮时,页面应上载照片并将用户重定向到另一个链接 回声“
”; 回声'; 回声'; }
我想这正适合你的需要

<!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>

webpeaks.in |将图像上传到Facebook
html{
字体系列:“lucida grande”,tahoma,verdana,arial,无衬线;
}
梅因先生{
宽度:400px;
保证金:自动;
边框:2个实心#0066CC;
颜色:#3B5998;
填充:20px;
字体大小:11px;
-moz边界半径:4px4px4px4px;
边界半径:4px4px4px4px;
-莫兹盒阴影:1px1px0#d5d5;
背景:无重复滚动0 0#f2f2;
}
.post_但是{
背景:无重复滚动0 0#EEEEEE;
边框颜色:#999999#999999#8888888;
边框样式:实心;
边框宽度:1px;
颜色:#333333;
光标:指针;
显示:内联块;
字体大小:11px;
字体大小:粗体;
填充:2px6px;
文本对齐:居中;
文字装饰:无;
}
a{
颜色:#3B5998;
}

您希望在什么时候在上述代码中执行重定向?在上面的代码片段中添加注释,让我们知道。