【问题标题】:Emailing Photos to my Facebook Page通过电子邮件将照片发送到我的 Facebook 页面
【发布时间】:2012-02-10 19:37:27
【问题描述】:

我们运行 facebook 粉丝页面 www.facebook.com/GowerLive,其中包含来自 Gower 半岛的 3 个网络摄像头的图像和更新;我想使用 Facebook 上的功能,该功能允许您在每天晚上 8 点使用 CRON 作业中的唯一电子邮件地址将照片直接通过电子邮件发送到您的粉丝页面。

我已经测试了电子邮件地址...效果很好,我可以提交图像,但是我的 PHP 脚本不显示照片。它会将主题发布到 facebook,仅此而已。

首先,这是将图片上传到我的粉丝页面的最佳方式吗?
其次,我是否使用了正确的电子邮件格式才能像 Multipart Mime Type 一样工作?
这是我目前在 cron 上运行的脚本

// array with filenames to be sent as attachment
 $files = array("public_html/langcam/09.jpg","public_html/langcam/13.jpg","public_html/langcam/16.jpg","public_html/caswellcam/09.jpg","public_html/caswellcam/13.jpg","public_html/caswellcam/16.jpg","public_html/llangcam/09.jpg","public_html/llangcam/13.jpg","public_html/llangcam/16.jpg"); 

// email fields: to, from, subject, and so on
$to = "uniqueaddress@m.facebook.com";
$from = "email@mysite.com";
$subject = "On ".date("F j, Y")." the wavebuoy at 1pm was ". $waveheightb."ft @ ".$seconds."seconds with a ".$windcompass." wind at ".$windspeedb."mph"; 
$message = "I normally leave this blank";
$headers = "From: $from";

// boundary 
$semi_rand = md5(time()); 
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 

// headers for attachment 
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; 

// multipart boundary 
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; 
$message .= "--{$mime_boundary}\n";

// preparing attachments
for($x=0;$x<count($files);$x++){
    $file = fopen($files[$x],"rb");
    $data = fread($file,filesize($files[$x]));
    fclose($file);
    $data = chunk_split(base64_encode($data));
    $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" . 
    "Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" . 
    "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
    $message .= "--{$mime_boundary}\n";
}

// send

$ok = @mail($to, $subject, $message, $headers); 
if ($ok) { 
    echo "Mail sent to $to!"; 
} else { 
    echo "Mail could not be sent!"; 
}

谢谢

【问题讨论】:

  • 如果您将电子邮件发送给自己而不是 facebook - 您会看到图片吗?
  • 是的,尽管我必须稍微更改脚本才能使其与 CRON 一起使用,但仅限于我使用的文件路径中。要将它与 CRON 一起使用,我在图像之前添加了 public_html/ 并且我没有收到任何错误。我认为可能导致问题的原因是电子邮件的进一步附件是一个名为 ATT00036.txt 的文件……知道那个文件是什么吗?
  • 我让这个晚上运行 CRON 工作,但我编辑了代码,所以它抄送了我的个人电子邮件地址,以确保图像肯定被附加,它通过 OK 发送到我的个人电子邮件,但只有将主题行发布到 Facebook!非常令人沮丧。

标签: php facebook email upload photos


【解决方案1】:

李,

您可能想查看 Facebook Graph API。我不确定它是否适用于粉丝页面,但没有理由不这样做。忽略博文标题并向下滚动到文章的第二部分,了解如何创建相册并将照片上传到其中。

https://developers.facebook.com/blog/post/498/

与照片有关的 Facebook Graph API 页面位于以下 URL:

http://developers.facebook.com/docs/reference/api/photo/

或者在http://ifttt.com 上创建一个 ifttt 脚本,因为它可能更容易。

乔恩

【讨论】:

    猜你喜欢
    • 2012-11-17
    • 1970-01-01
    • 2015-11-03
    • 1970-01-01
    • 2012-05-18
    • 1970-01-01
    • 2015-12-07
    • 1970-01-01
    • 2010-10-25
    相关资源
    最近更新 更多