douzhong1730 2013-02-14 18:25
浏览 46
已采纳

在页面时间轴上传Facebook照片(PHP)

I have a cache of pictures in my website, and I need to upload these photos to my Facebook fan page 4-5 times a day. My code creates an album and also uploads the photos to the album, however, these photos do not appear in the timeline.

So my question is, how do I upload photos to my fan page such that they appear on the timeline, on the wall. The language in use is PHP

Any help is greatly appreciated.

Thanks

Edit 1: Here is the code:

<?php   
require 'facebook.php';
$facebook = new Facebook(array(
    'appId'  => "AAAAAAAAAA",
    'secret' => "BBBBBBBBBB",
));

$fanpage_token = "ZZZZZZZZZZZZZZZZZZZZZZZZZZ";

$facebook->setFileUploadSupport(true);

//Create an album
$album_details = array(
        'message'=> 'test album',
        'name'=> 'album'
);
$create_album = $facebook->api('/PAGE_ID/albums', 'post', $album_details);

$album_uid = $create_album['id'];

echo $album_uid;

 $img = '7newx.jpg';
  $args = array(
   'message' => 'Random message',
   'image' => '@' . $img,
   'aid' => $album_uid,
   'no_story' => 1,
   'access_token' => $fanpage_token
  );

  $photo = $facebook->api($album_uid . '/photos', 'post', $args);

?>
  • 写回答

1条回答 默认 最新

  • dpwh11290 2013-02-14 22:35
    关注

    Ok, so I guess you tried removing the no_story and found that it didn't affect the timeline. Thats what I found too.

    What you have to do is make another post, but this time, as a link. You need to use your array $photo, which was returned from your first post. If you examine that you should see it has a single element called ['id'], containing the id of your uploaded photo.

    You need to turn that into a link that facebook would use to display. This is simple.

    if (isset($photo['id']))
    {
    $message = "My latest photo";
    $link = "https://www.facebook.com/photo.php?fbid=".$photo['id'];
    $attachment = array
    (
    'access_token'=>$fanPageAccessToken,
    'type' => 'photo',
    'message' => $message,
    'link' => $link 
    );
    
    $result = $facebook->api($fanPageId.'/links/','post',$attachment);
    }
    

    I am assuming you can work out what $fanPageAccessToken and $fanPageId are.

    If you do that, you should get what you want.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化