Tweet to twitter or post to facebook by user's credentials in the PHP
I have a form with 2 fields (username, password) and a select box (Facebook or Twitter). I have also registered applications with Facebook and Twitter. Is there some way to post to a user's wall in Facebook or to tweet to a use开发者_运维知识库r's Twitter account?
I have found some libraries for PHP such as Facebook-SDK and TwitterOAuth, but I can't find this functionality in them. Is it possible?
Thank you in advance.
It's possible to post to twitter by using only username and password. Without the need for user to connect to your twitter application. I've done this using twitter's XAuth authentication. I'm not sure about facebook. Never build an app for it.
However, since you use web application, it's recommended that you use OAuth. I've used Abraham's OAuth library before. The exact API function you needed is:
$connection->post('statuses/update', array('status' => "this status sent from twitter OAUTH API"));
Try download the whole project and and upload it to your server, and run it. Don't forget to set CONSUMER_KEY and CONSUMER_SECRET of your application.
I've used this library to construct a tweet application. https://github.com/abraham/twitteroauth
I've also used this library with CodeIgniter http://www.haughin.com/code/twitter/
Hope this helps.
For reference sake: use this library php-twitter as its the simplest I have used and it just works.
精彩评论