代码之家  ›  专栏  ›  技术社区  ›  homework

Twitter后台上传API和多表单数据

  •  1
  • homework  · 技术社区  · 15 年前

    为什么我的图像上传总是失败? 图像更新方法需要 多部分表单数据。他们没有 接受图像的URL不是吗 以文件上传的形式交付。

    有没有人就此得出结论,或者解决了这个问题?我在试图让它发布图片时遇到了各种各样的麻烦。

    1 回复  |  直到 15 年前
        1
  •  2
  •   dragonmantank    15 年前

    你到底有什么问题?从API的声音来看,您只需要定期将文件上传到Twitter本身。以下内容允许您将文件上载到服务器,并通过 API docs :

    <?php
        if( $_POST ) {
            // Do anything needed for authentication
            $ch = curl_init('http://twitter.com/account/update_profile_background_image.xml');
            curl_setopt_array(array(
                CURLOPT_POSTFIELDS => array('image' => '@'.$_FILES['myfile']['tmp_name']),
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_POST => true,
            ));
    
            $rsp = curl_exec($ch);
            // Read the response
        }
    ?>
    <form enctype="multipart/form-data" method="post">
        File: <input type="file" name="myfile" />
        <input type="submit">
    </form>
    

    更多信息可在 PHP documentation cURL documentation 对于PHP。