【问题标题】:Uploading Photos from Hard Drive to Facebook using the API使用 API 将照片从硬盘上传到 Facebook
【发布时间】:2010-10-18 14:01:41
【问题描述】:

想知道是否有人可以帮助我。几天来,我一直在寻找有关如何使用 API 将照片发布到 Facebook 的帮助。我遇到了以下脚本,该脚本似乎对每个人都有效,但是我不确定如何将其连接到用户可以从硬盘驱动器中选择照片并上传的表单。谁能指出我正确的方向?

PHP 代码:

$token = $session['access_token'];
$file= 'photo.jpg';
$args = array(
'message' => 'Photo from application',
);
$args[basename($file)] = '@' . realpath($file);

$ch = curl_init();
$url = 'https://graph.facebook.com/me/photos?access_token='.$token;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$data = curl_exec($ch);

表格代码:

<form action="<?=$PHP_SELF;?>" enctype="multipart/form-data" method="POST"> 
 <input name="MAX_FILE_SIZE" type="hidden" value="10000000" /> 
 <input id="file" name="file" type="file" /> 
 <input name="submit" type="submit" value="Upload" />
</form>

【问题讨论】:

    标签: php facebook photo facebook-graph-api


    【解决方案1】:

    克拉克,

    php 脚本在 $_FILES 变量中接收文件及其详细信息。

    例如。如果您要上传文件名 Image1.jpg,则 $_FILES 数组将具有以下值

    数组(1){ [“文件”]=> 数组(5){ [“名称”]=> 字符串(21)“Image1.jpg” [“类型”]=> 字符串(10)“图像/JPEG” ["tmp_name"]=> 字符串(23) "C:\wamp\tmp\phpD1DF.tmp [“错误”]=> int(0) [“大小”]=> 整数(355315) } }

    这里,name = 实际文件名 类型 = 文件类型 tmp_name = 文件上传到服务器的临时位置路径 大小 = 文件大小

    为了将文件上传到 facebook,您应该对 "name""tmp_name" 感兴趣的值。

    因此,您应该发送到 facebook 以上传照片的参数应该是这样的

    $args = 数组( '消息' => '来自应用程序的照片', );

    $args[$_FILES['file']['name']] = '@' 。 $_FILES['file']['tmp_name'];

    我认为这应该适合你。

    顺便说一句,我查看了照片上传的 facebook 文档@http://developers.facebook.com/docs/reference/api/photo 他们说文件名应该在参数“源”中传递,所以如果上述参数不适合你,你可以试试

    $args = 数组( '消息' => '来自应用程序的照片', '来源' => '@' 。 $_FILES['file']['tmp_name'] );

    试一试 :) 希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 2012-08-19
      • 2011-02-03
      • 1970-01-01
      • 1970-01-01
      • 2011-04-08
      相关资源
      最近更新 更多