0

i use the following function to post to twitter, it returns a success message but the tweet does not appear on the twitter timeline. Note the website is on my localhost using WAMP. i enabled curl .

function below :

         function Post_to_twitter($message){
     // Set username and password
         $username = 'myaccountusername';
         $password = 'mypass';
         // set the twitter API address
         $url = 'http://twitter.com/statuses/update.json';
         // setup a curl process
         $curl_handle = curl_init();
         // set the url of the curl process
         curl_setopt($curl_handle, CURLOPT_URL, "$url");
         // saves the return value as a string value instead of outputting to browser
         curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
         // to send data as $_POST fields as required by the twitter API
         curl_setopt($curl_handle, CURLOPT_POST, 1);
         // set the post fields
         curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
         // set the username and password for the connection
         curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
         // exectute the curl request and save output as $buffer variable
         $buffer = curl_exec($curl_handle);
         // close the curl connection
         curl_close($curl_handle);
         // decode json output into array
         $json_output = json_decode($buffer, true);
         $status = '' ;
         // check for success or failure
         if (isset($json_output['error'])) {
            // tweet not successful, display error
          $status = 'failed' ;
         }
         else {
         $status = 'succesful' ;
         }
         return $status ;
         }

         echo Post_to_twitter('Hello world');
4

1 回答 1

1

Twitter 已更新其 API。现在需要通过 OAuth 进行身份验证。

您可以在此处阅读有关 Twitter 身份验证的更多信息。

于 2013-10-26T18:46:35.233 回答