{"id":123,"date":"2009-06-22T15:18:44","date_gmt":"2009-06-22T19:18:44","guid":{"rendered":"http:\/\/www.dev-notes.com\/blog\/2009\/06\/22\/update-twitter-status-programmatically-with-php-and-curl\/"},"modified":"2009-06-22T15:18:44","modified_gmt":"2009-06-22T19:18:44","slug":"update-twitter-status-programmatically-with-php-and-curl","status":"publish","type":"post","link":"https:\/\/www.dev-notes.com\/blog\/2009\/06\/22\/update-twitter-status-programmatically-with-php-and-curl\/","title":{"rendered":"Update Twitter status programmatically with PHP and cURL"},"content":{"rendered":"<pre class=\"code\">\nfunction twitterUpdate($u, $p, $upd) {\n\t\/\/ $u is your username (string)\n\t\/\/ $p is your password (string)\n\t\/\/ $upd is your status update (string)\n\n\t$url = 'http:\/\/twitter.com\/statuses\/update.xml';\n\n\t$curl_handle = curl_init();\n\tcurl_setopt($curl_handle, CURLOPT_URL, $url);\n\tcurl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);\n\tcurl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);\n\tcurl_setopt($curl_handle, CURLOPT_POST, 1);\n\tcurl_setopt($curl_handle, CURLOPT_POSTFIELDS, \"status=\".$upd);\n\tcurl_setopt($curl_handle, CURLOPT_USERPWD, $u.\":\".$p);\n\t$buffer = curl_exec($curl_handle);\n\tcurl_close($curl_handle);\n\n\tif (empty($buffer)) {\n\t\treturn 'fail';\n\t}\n\telse {\n\t\treturn 'success';\n\t}\n}\n<\/pre>\n<p>Example usage is below.<\/p>\n<pre class=\"code\">\n$u='username';\n$p='password';\n$upd='Hello world!';\n\n$twitterUpdateResult = twitterUpdate($u, $p, $upd);\n\necho $twitterUpdateResult;\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This note provides a sample PHP function that updates your Twitter status, making use of the cURL module.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-123","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts\/123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/comments?post=123"}],"version-history":[{"count":0,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts\/123\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/media?parent=123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/categories?post=123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/tags?post=123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}