2012-04-01 10 views
0

次のコードを使用して、画像をラックスペースのcdnアカウントにアップロードしています。アップロードは正常に動作します。私がtweetbotから写真をつぶやくと、自動的に私のラックスペースcdnにアップロードされます。私がやりたいことは、私がツイートしたメッセージを取り出して、メッセージと写真のリンクをデータベースに挿入することです。ここでユーザのツイートを取得してdbに挿入する

は私がこれまで何をしたか..です

$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 = isset($userInfo['message']) ? $userInfo['message'] : null; 

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

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

        // cloud info 
        $username = 'username'; // username 
        $key ='apikey' ; // api key 
        $container = '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(); 


        echo '<mediaurl>http://url/'.$nf.'</mediaurl>'; 

        $link = 'http://url/'.$nf ; 


        $con = mysql_connect("localhost","username","password"); 
        if (!$con) 
         { 
          die('Could not connect: ' . mysql_error()); 
         } 

        mysql_select_db("database", $con); 

        mysql_query("INSERT INTO photo (link)VALUES ('$link','$tweet')"); 


        mysql_close($con); 

} else { 
    // verification failed, we should return the error back to the consumer 
    $response = json_decode($oauthecho->responseText, true);  
    $message = isset($response['error']) ? $response['error'] : null;  
    if (!headers_sent()) 
    header('HTTP/1.0 ' . $oauthecho->resultHttpCode); 
    echo $message; 
    } 

は、私はいくつかの写真をアップロードしました。アップロードは正常に動作し、URLはtweetbotに返されます。しかし、何も私のDBに追加されません。ヘルプしてください

+0

あなたは 'mysql_error()'の出力をチェックしていません... – PeeHaa

答えて

0

あなたは2つのフィールドに挿入しようとするが、1つのフィールド名のみ宣言:あなたがこれを見てmysql_errorを使用することができます

INSERT INTO photo (link, tweet) VALUES ('$link','$tweet') 

:あなたのような何かをする必要があり

INSERT INTO photo (link)VALUES ('$link','$tweet') 

を次回

+0

私はそれを修正しましたが、まだ動作しませんでした。 –

+0

エラーは何ですか? 、mysql_errorを試してください –

+0

はリンクでは動作しますが、ツイートを取得できませんでした http://d.pr/5Ths –

関連する問題