How to post a message from PHP page to twitter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dinesh1985singh
    New Member
    • Apr 2010
    • 49

    How to post a message from PHP page to twitter

    Hi everyone,

    I want to post a message from a php page to twitter account.
    like i want to post message to twitterId:dines h1985singh for that I am using given code: but it doesn't working

    Code:
    <?php
    	
    	$username = 'xyz';
    	$password = 'pwd';
    	$message = 'hii';
        $host = "http://twitter.com/statuses/update.xml?status=".urlencode(stripslashes(urldecode($message)));
    
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $host);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
    	curl_setopt($ch, CURLOPT_HEADER, 1); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    	curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
        curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($ch, CURLOPT_POST, 1);
    	
        $returnData = curl_getinfo($ch); 
        $result = curl_exec($ch);
        // Look at the returned header
        $resultArray = curl_getinfo($ch);
    
        curl_close($ch);
    	
    	echo "<pre/>";
    	print_r($resultArray);
    	
    	
       
    ?>
    I google it out lot for this but didn't get success.
    Can anyone suggest me where would i made mistake.




    Thanks
    Last edited by Atli; Sep 22 '10, 07:57 PM. Reason: Please use [code] tags when posting code.
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Sorry dinesh1985singh , we can't debug your code.

    We can help you once you found out what the problem is.

    What have you done to troubleshoot it?

    Where does the code break?

    What is its actual output vs expected output?

    Any Errors?

    At Bytes, we tend to help fix the programmer, not the program.

    Dan

    Comment

    • dinesh1985singh
      New Member
      • Apr 2010
      • 49

      #3
      Thank you dlite922 ,not an issue
      The output is something like this

      Code:
      Array
      (
          [url] => http://twitter.com/statuses/update.xml?status=hello+twitterati%21+I%27m+posting+this+from+a+PHP+script%21+woo%21
          [http_code] => 0
          [header_size] => 0
          [request_size] => 271
          [filetime] => -1
          [ssl_verify_result] => 0
          [redirect_count] => 0
          [total_time] => 0.003812
          [namelookup_time] => 0.001563
          [connect_time] => 0.003758
          [pretransfer_time] => 0.003764
          [size_upload] => 0
          [size_download] => 0
          [speed_download] => 0
          [speed_upload] => 0
          [download_content_length] => 0
          [upload_content_length] => -1
          [starttransfer_time] => 0.003805
          [redirect_time] => 0
      )
      eek! yegads! error posting to Twitter


      In this output i guess http_code must be 200 only then things will work out .

      Let me know if you have any suggestion realted to this.

      Thank you one more time for your quick response.
      Last edited by Atli; Sep 24 '10, 12:32 AM. Reason: Added [code] tags.

      Comment

      • dlite922
        Recognized Expert Top Contributor
        • Dec 2007
        • 1586

        #4
        I don't know where the problem is since I never worked with twitter, but if I ever start, I'd start here:




        Dan

        Comment

        • dinesh1985singh
          New Member
          • Apr 2010
          • 49

          #5
          Thank you by the way dlite for sharing this link.

          Comment

          Working...