0

下面是我上传图片、创建帖子和粉丝页面的代码。除了一件事之外,自动发布工作正常 - 当图像发布到相册时,粉丝页面时间轴上没有显示任何内容。您能帮我解决问题或指向一些文档吗?我试图用谷歌搜索它,但 stackoverflow 或 facebook 开发人员的结果都没有帮助我。

    $function ips_fanpage_post( $id, $row = false, $force_type = 'post' )
    {
    require_once( ABS_PATH . '/connect/facebook/facebook.php');
    if( !is_array( $row ) )
    {
        $row = PD::getInstance()->simpleSelect( IPS__FILES, "`id` = '$id'", 1);
        if( empty($row) )
        {
            ips_log( "ips_fanpage_post($id)" );
            return;
        }
        global ${IPS_LNG};
        $row['type'] = 'post';
        $row['caption'] = ${IPS_LNG}['meta_site_title'];
        $row['description'] = 'เยี่ยมไหม แย่ไหม ชอบไหม';
        $row['image'] = IMG_LINK . '/' . $row['img_url'];
        $row['link'] = seoLink($row['id'], $row['title']);
        $row['message'] = 'เยี่ยมไหม แย่ไหม ชอบไหม';
    }
    $image = null;
    if( !empty( $_FILES["file"]["tmp_name"] ) )
    {
        $image = realpath($_FILES["file"]["tmp_name"]);
    }
    else
    {
        if( file_exists( IMG_PATH . '/' . basename( $row['image'] ) ) )
        {
            $image = IMG_PATH . '/' . basename( $row['image'] );
        }
        elseif( file_exists( ABS_PATH . '/upload/img_obrazki/' . basename( $row['image'] ) ) )
        {
            $image = ABS_PATH . '/upload/img_obrazki/' . basename( $row['image'] );
        }
        elseif( file_exists( ABS_PATH . '/upload/import/' . basename( $row['image'] ) ) )
        {
            $image = ABS_PATH . '/upload/import/' . basename( $row['image'] );
        }
    }
    if( empty( $image ) )
    {
        return array('Nie można odnależć określonego obrazka.');
    }
    $fanpage_id = Config::GET('apps_facebook_fanpageid');
    $facebook = new Facebook(array(
        'appId'  => Config::GET('apps_facebook_appid'),
        'secret' => Config::GET('apps_facebook_appsecret'),
        'cookie' => true,
        'fileUpload' => true
    ));
    if( $row['type'] == 'upload' || $force_type == 'upload' )
    {
        $params = array(
            'access_token' => Config::GET('apps_facebook_token')
        );
        $accounts = $facebook->api('/me/accounts', 'GET', $params);
        foreach($accounts['data'] as $account)
        {
            if( $account['id'] == $fanpage_id || (isset($account['name']) && $account['name'] == $fanpage_id) )
            {
                $fanpage_token = $account['access_token'];
            }
        }
        $image = str_replace( '_middle', '', $image );
        if( !isset( $fanpage_token ) )
        {
            ips_log( 'Pusty $fanpage_token, prawdopodobnie nie jest adminem.' );
            return false;
        }

        $params = array(
            'message' => 'เยี่ยมไหม แย่ไหม ชอบไหม',
            'image' => '@' . $image,
            'no_story' => 1,
            'aid' => $row['album_id'],
            'access_token' => $fanpage_token
        );

        try
        {
            $rest = $facebook->api( '$row['album_id']' . '/photos', 'post', $params );
            if( $rest )
            {
                $data = array(
                    'id' => 'NULL',
                    'file_id' => $row['album_id'],
                    'post_id' => $rest['id'],
                    'title' => $row['title'],
                    'data' => date("Y-m-d H:i:s"),
                    'link_post' => 'https://www.facebook.com/photo.php?fbid=' . $rest['id'],
                    'type' => 'upload'
                );
                PD::getInstance()->insert("fanpage_post", $data);
                return true;
            }
            ips_log( $rest );
            return false;

        } catch (FacebookApiException $e) {
            ips_log($e);
            return $e->getMessage();
        }
    }
    else
    {
        $image = str_replace( ABS_PATH, substr( ABS_URL, 0 , -1 ), $image );
        if( substr( $image, 0 , 4 ) != 'http' )
        {
            $image = substr( ABS_URL, 0 , -1 ) . $image;
        }
            $attachment = '{
                            "name":"คลิกที่นี่ ตอนนี้",
                            "href":"'. $row['link'] .'",
                            "caption":"'. $row['caption'] .'",
                            "description":"'. $row['description'] .'",
                            "properties":null,
                            "media":[{
                                "type":"image",
                                "src":"' . $image . '",
                                "href":"' . $row['link'] . '",
                                }],
                            "auto_publish":true
                        }';
            try {
                $rest = $facebook->api(array(
                    "uid"          => $fanpage_id,
                    "method"       => "stream.publish",
                    "access_token" => Config::GET('apps_facebook_token'),
                    "message"      => $row['message'],
                    "attachment"   => $attachment,
                    "caption"       => $row['caption']
                ));
                if( $rest )
                {
                    $data = array(
                        'id' => 'NULL',
                        'file_id' => $id,
                        'post_id' => $rest,
                        'title' => $row['title'],
                        'data' => date("Y-m-d H:i:s"),
                        'link_post' => 'https://www.facebook.com/'. str_replace('_', '/posts/',  $rest),
                        'type' => 'post'
                    );
                    PD::getInstance()->insert("fanpage_post", $data);
                    return true;
                }
                ips_log( $rest );
                return false;
            } catch (FacebookApiException $e) {
                /**
                * Błąd zapisany do pliku log
                */
                ips_log($e);
                return false;
            }
    }

    }
4

1 回答 1

1

https://developers.facebook.com/docs/reference/api/page/#photos

no_story:如果设置为 1,可选择禁止在您上传照片时在页面上自动生成的提要故事。

于 2013-10-16T07:52:07.587 回答