"Yesterday is gone and Tomorrow may never come so.. Live for Today!!"
โค้ด Tweet ผ่าน PHP
6 Oct 2009 02:04   [4260 views]

เผอิญตะกี้คุยกับ @iGimme เรื่องทวีตผ่าน PHP วันนี้เลยเอา Source มาแปะให้ เผื่อมีใครสนใจจะเอาไปใช้ ^ ^

function Tweet($username, $password, $msg)
{
$message = $msg;

$ip = gethostbyname("twitter.com");
$sock = fsockopen($ip, 80, $errno, $errstr, 60);
fputs($sock, "POST /statuses/update.xml HTTP/1.1
Host: twitter.com
Authorization: Basic " . base64_encode($username . ":" . $password) . "
Content-Length: " . (strlen($message) + 7) . "

status=" . $message);
$return = "";
while (!feof($sock)) {
$return .= fgets($sock, 4096);
}
fclose($sock);
}

เวลาจะเรียกใช้ก็พิมพ์ว่า

Tweet("username", "password", "Hello World");

หมายเหตุ: โค้ดตรงบรรทัดที่ชิดซ้ายอย่าไปเอาจัดย่อหน้าเองเป็นอันขาด มันต้องอยู่ชิดซ้ายอย่างงั้น ไม่งั้น HTTP Request จะมีปัญหาทันที ทางที่ดีก็อปแปะแล้วเอาไปใช้เลยจะเวอร์คที่สุดครับผม


ปล. goddady ทวีตไม่ได้แล้ว ไม่รู้เป็นอะไร แต่ก่อนยังได้อยู่เลย ไม่รู้ว่า godaddy block twitter หรือ twitter block godaddy แต่ไม่ว่าจะยังไง... อีเนยไม่ปลื้มมมม เซ็ง :(

บทความที่เกี่ยวข้อง

Feb 3, 2010, 04:35
3848 views
Google Apps บอกลา IE6
Feb 15, 2010, 18:41
5646 views
Symbian^3 UI Design Preview
0 Comment(s)
Loading