473,325 Members | 2,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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 4489
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

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

Similar topics

0
by: HakonB | last post by:
Hi all I get an exception when trying to deserialize a simple configuration file using XML Serialization. The very long stacktrace can be seen at the bottom of this message. I've see other...
8
by: Alberto | last post by:
Can you tell me how to read and modify a value in the app.config file using this class? Thank you very much
0
by: daftspaniel | last post by:
I have launched a Twitter service called pythonnews - News about the Python Programming Language brought to you on Twitter! If you want to publicise something Python related just direct message...
4
by: David Williams | last post by:
I am familiar with creating custom configuration settings and accessing them. However, for a current requirement, I need to control the various settings in my custom configuration section by...
2
by: 4bret | last post by:
I'm a web developer with experience in mostly front-end coding languages but I am very interested in learning more about the Twitter API. I have spent a decent amount of time reading the Twitter API...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.