472,328 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 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 4444
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...
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...
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...
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...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.