cURL - 有没有一种方法可以在没有表单的情况下将视频上传到 Facebook?
我有一些curl代码,它们可以成功地将任何文件上传到我的任何主机。
但我想在没有任何形式的情况下将视频上传到 Facebook。它在 Facebook 上不起作用。
以下是代码:
<?php
$app_id = "23***************";
$app_secret = "******************";
$my_url = "http://localhost/fbupload/";
$video_title = "Test";
$video_desc = "Test";
$code = $_REQUEST["code"];
if(empty($code)) {
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&scope=publish_stream";
echo("<script>top.location.href='" . $dialog_url . "'</script>");
}
$token_url = "https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;
$access_token = file_get_contents($token_url);
$post_url = "https://graph-video.facebook.com/me/videos?"
. "title=" . $video_title. "&description=" . $video_desc
. "&". $access_token;
//CURL CODES START
<前><代码> $ch = curl_init(); $data = array('名称' => '文件', '文件' => '@/1.mp4'); curl_setopt($ch, CURLOPT_URL, $post_url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 卷曲执行($ch);
//CURL ENDS
?>
如果我改变curl来形成它就可以了。
echo '
你有什么建议?我的错在哪里?
I have some curl codes and they upload any file to any host of me successfully.
But i want to upload a video to facebook without any form. It doesn't work on facebook.
Here are codes:
<?php
$app_id = "23***************";
$app_secret = "******************";
$my_url = "http://localhost/fbupload/";
$video_title = "Test";
$video_desc = "Test";
$code = $_REQUEST["code"];
if(empty($code)) {
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&scope=publish_stream";
echo("<script>top.location.href='" . $dialog_url . "'</script>");
}
$token_url = "https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;
$access_token = file_get_contents($token_url);
$post_url = "https://graph-video.facebook.com/me/videos?"
. "title=" . $video_title. "&description=" . $video_desc
. "&". $access_token;
//CURL CODES START
$ch = curl_init(); $data = array('name' => 'file', 'file' => '@/1.mp4'); curl_setopt($ch, CURLOPT_URL, $post_url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_exec($ch);
//CURL ENDS
?>
if i change curl to form it works.
echo '<form enctype="multipart/form-data" action="'.$post_url.' "method="POST">'; echo 'Please choose a file:'; echo '<input name="file" type="file">'; echo '<input type="submit" value="Upload" />'; echo '</form>';
What do you suggest? where is my fault?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个更好的代码:
重要说明:
realpath()
来获取文件的真实路径,curl_close($ch)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); ,否则代码将无法在本地主机上工作,但使用后者是不建议(请参阅此)
Here's a better code:
IMPORTANT NOTES:
realpath()
to get the real path of the filecurl_close($ch)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
but using the later is NOT adviced (refer to this)makeRequest()
method in base_facebook.php