1

所以我为推特机器人做了一个自定义媒体上传服务。图片上传就好了,推特机器人返回并发布了 URL。但是,当我尝试上传视频时,它会检索 URL,但会发生这种情况:

http://c0728267.cdn2.cloudfiles.rackspacecloud.com/1333560894-movie.mp4

注意到顶部文本前面的图像了吗?然而这是一个视频。我究竟做错了什么?

这是上传过程的代码

$oauthecho = new TwitterOAuthEcho();
$oauthecho->userAgent = 'dpkgme test app';
$oauthecho->setCredentialsFromRequestHeaders();

if ($oauthecho->verify()) {      

 // Verification was a success, we should be able to access the user's Twitter info from the responseText.
 $userInfo = json_decode($oauthecho->responseText, true);
 $twitterId = isset($userInfo['id']) ? $userInfo['id'] : null;


                    $tweet = $_POST['message'];

                    error_reporting(E_ALL);
                    ini_set('display_errors', 1);

                    // include the API
                    require("cloudfiles.php") ;

                    // cloud info
                    $username = ''; // username
                    $key ='' ; // api key
                    $container = ''; // container name

                    ob_start();


                    $localfile = $_FILES['media']['tmp_name'];
                    $filename = $_FILES['media']['name'];
                    $nf = time().'-'.$filename; 


                    ob_flush();

                    // Connect to Rackspace
                    $auth = new CF_Authentication($username, $key);
                    $auth->authenticate();
                    $conn = new CF_Connection($auth);

                    // Get the container we want to use
                    $container = $conn->create_container($container);

                    // store file information

                    ob_flush();

                    // upload file to Rackspace
                    $object = $container->create_object($nf);
                    $object->load_from_filename($localfile);

                    $uri = $container->make_public();
                    //print "Your URL is: " . $object->public_uri();

                    $imagePageUrl = $object->public_uri();


                    ob_end_flush();


$link = 'http://c0728267.cdn2.cloudfiles.rackspacecloud.com/'.$nf ; 

$shortenedurl = file_get_contents('http://gl.gy/index.php?url='.$link);
$keys = parse_url($shortenedurl); // parse the url
    $path = explode("/", $keys['path']); // splitting the path
    $last = end($path); // get the value of the last element 


    echo '<mediaurl>http://gl.gy/'.$last.'</mediaurl>';
4

1 回答 1

0

解决了。我添加了内容类型检测。现在工作正常。

于 2012-04-05T18:05:28.670 回答