469,269 Members | 1,006 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,269 developers. It's quick & easy.

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:dinesh1985singh for that I am using given code: but it doesn't working

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.     $username = 'xyz';
  4.     $password = 'pwd';
  5.     $message = 'hii';
  6.     $host = "http://twitter.com/statuses/update.xml?status=".urlencode(stripslashes(urldecode($message)));
  7.  
  8.     $ch = curl_init();
  9.     curl_setopt($ch, CURLOPT_URL, $host);
  10.     curl_setopt($ch, CURLOPT_VERBOSE, 1);
  11.     curl_setopt($ch, CURLOPT_HEADER, 1); 
  12.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  13.     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
  14.     curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
  15.     curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  16.     curl_setopt($ch, CURLOPT_POST, 1);
  17.  
  18.     $returnData = curl_getinfo($ch); 
  19.     $result = curl_exec($ch);
  20.     // Look at the returned header
  21.     $resultArray = curl_getinfo($ch);
  22.  
  23.     curl_close($ch);
  24.  
  25.     echo "<pre/>";
  26.     print_r($resultArray);
  27.  
  28.  
  29.  
  30. ?>
I google it out lot for this but didn't get success.
Can anyone suggest me where would i made mistake.




Thanks
Sep 22 '10 #1
4 4363
dlite922
1,584 Expert 1GB
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
Sep 22 '10 #2
Thank you dlite922 ,not an issue
The output is something like this

Expand|Select|Wrap|Line Numbers
  1. Array
  2. (
  3.     [url] => http://twitter.com/statuses/update.xml?status=hello+twitterati%21+I%27m+posting+this+from+a+PHP+script%21+woo%21
  4.     [http_code] => 0
  5.     [header_size] => 0
  6.     [request_size] => 271
  7.     [filetime] => -1
  8.     [ssl_verify_result] => 0
  9.     [redirect_count] => 0
  10.     [total_time] => 0.003812
  11.     [namelookup_time] => 0.001563
  12.     [connect_time] => 0.003758
  13.     [pretransfer_time] => 0.003764
  14.     [size_upload] => 0
  15.     [size_download] => 0
  16.     [speed_download] => 0
  17.     [speed_upload] => 0
  18.     [download_content_length] => 0
  19.     [upload_content_length] => -1
  20.     [starttransfer_time] => 0.003805
  21.     [redirect_time] => 0
  22. )
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.
Sep 23 '10 #3
dlite922
1,584 Expert 1GB
I don't know where the problem is since I never worked with twitter, but if I ever start, I'd start here:

http://apiwiki.twitter.com/


Dan
Sep 23 '10 #4
Thank you by the way dlite for sharing this link.
Sep 25 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

By using this site, you agree to our Privacy Policy and Terms of Use.