ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

php – 通过电子邮件发送照片到我的Facebook页面

2019-07-09 21:28:41  阅读:295  来源: 互联网

标签:php upload facebook email photos


我们运行Facebook粉丝页面www.facebook.com/GowerLive,其中包含我们在高尔半岛上的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 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脚本,因为它可能更容易.

乔恩

标签:php,upload,facebook,email,photos
来源: https://codeday.me/bug/20190709/1416954.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有