Twitter的背景与上传API和多形式的数据 [英] Twitter background upload with API and multi form data

查看:177
本文介绍了Twitter的背景与上传API和多形式的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Twitter的API部分服用。

Taken from the Twitter's API section.

为什么我的图片上传总是失败?
  图像更新方法需要
  多部分表单数据。他们不
  接受一个URL到图像不做他们
  接受的原始图像字节。他们
  代替要求数据是
  在文件上传的形式交付。

Why do my image uploads always fail? The image update methods require multipart form data. They do not accept a URL to an image not do they accept the raw image bytes. They instead require the data to be delivered in the form of a file upload.

有没有人得出的结论与此,还是解决这个问题?我有不同数量的麻烦试图让它张贴的图像。
我环顾四周,发现没有解决这个问题。

Has anyone came to a conclusion with this, or resolved this issue? I'm having various amounts of trouble trying to get it to post an image. I've looked around and found no solutions with this.

推荐答案

什么确切的问题,你有?从API的声音,你只需要做一个普通的文件上传到Twitter本身。下面,您可以将文件上传到服务器,并通过<一个推到Twitter href=\"http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-account%C2%A0update%5Fprofile%5Fbackground%5Fimage\"相对=nofollow> API文档:

What exact problems are you having? From the sounds of the API, you just need to do a regular file upload to Twitter itself. The following allows you to upload a file to your server and push it to Twitter via the 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文档发现卷曲文档为PHP。

这篇关于Twitter的背景与上传API和多形式的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆