【问题标题】:twitter api post being cut offtwitter api 帖子被截断
【发布时间】:2010-12-07 01:35:39
【问题描述】:

我使用以下代码将更新发布到 twitter:

// Set username and password for twitter API
        $username = '***';
        $password = '***';

        // The twitter API address
        $url = 'http://twitter.com/statuses/update.xml';

        // Alternative JSON version
        // $url = 'http://twitter.com/statuses/update.json';

        // Set up and execute the curl process
        $curl_handle = curl_init();

        curl_setopt($curl_handle, CURLOPT_URL, "$url");
        curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 10);
        curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl_handle, CURLOPT_POST, 1);
        curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$update");
        curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");

        $buffer = curl_exec($curl_handle);

        curl_close($curl_handle);

        // check for success or failure

        if (empty($buffer)) 
        {
            echo 'error?!';
        } 
        else 
        {
            // mark the song as tweetered
            mysql_query("UPDATE `songs` SET `tweet` = '1' WHERE `id` = $songid ");
        }
    }

    echo $update;

帖子功能正常,但由于某种原因被切断了。

例如上面的代码会在推特上发布:Tiesto - Feel It In My Bones (Feat. Tegan

何时发布:Tiesto - Feel It In My Bones (Feat. Tegan & Sara) - 160Kbps http://bit.ly/5mdCK4

我使用 echo $update;最后一行将 twitter 的输出与$update 值进行比较,$update 是正确的。

【问题讨论】:

    标签: php api curl twitter


    【解决方案1】:

    您是否尝试过其他输入字符串?从您在那里发布的内容来看,我敢打赌您的问题是状态中的 & 符号,因为这是表单帖子中的元字符。我确信 PHP 有一些对字符串进行 URL 编码的功能,你会想在 $update 上使用它。

    【讨论】:

    • 我现在正在检查。我认为我的代码以前使用过 & 和其他符号,但我正在浏览所有帖子。
    • 为什么要转发?这里有答案。
    【解决方案2】:

    十六奥托是对的。你需要做的:

    $update =urlencode($update);

    防止特殊字符出现问题。

    【讨论】:

    • 哦,嘿,它甚至被命名为合适的东西! :-)
    猜你喜欢
    • 2020-08-02
    • 2016-12-07
    • 2012-09-09
    • 2017-06-13
    • 1970-01-01
    • 1970-01-01
    • 2015-11-24
    • 2012-06-16
    • 1970-01-01
    相关资源
    最近更新 更多