Keine Lust dich in Facebook einzuloggen? Oder du willst Funktionen automatisieren, wie z.B. deine neusten WordPress – Artikel in FB posten? Dann hilft dir folgender Code
<?PHP
/*******************************
* Facebook Status Updater
* Christian Flickinger
* http://nexdot.net/blog
* April 20, 2007
*******************************/
$status = 'YOUR_STATUS';
$first_name = 'YOUR_FIRST_NAME';
$login_email = 'YOUR_LOGIN_EMAIL';
$login_pass = 'YOUR_PASSWORD';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php');
curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($login_email).'&pass='.urlencode($login_pass).'&login=Login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_exec($ch);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/home.php');
$page = curl_exec($ch);
curl_setopt($ch, CURLOPT_POST, 1);
preg_match('/name="post_form_id" value="(.*)" \/>'.ucfirst($first_name).'/', $page, $form_id);
curl_setopt($ch, CURLOPT_POSTFIELDS,'post_form_id='.$form_id[1].'&status='.urlencode($status).'&update=Update');
curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/home.php');
curl_exec($ch);
?>
Du möchtest gerne, dass auch andere in deinem Blog posten können, oder dir einen Desktop-Clienten basteln? Dann dient dieser Code als Gedankenstütze. Wichtig ist das du die XMLRCP Schnittstelle in WordPress aktivierst und der Server XML unterstützt ( tun aber inzwischen fast alle Hoster ).
function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$category,$keywords='',$encoding='UTF-8')
{
$title = htmlentities($title,ENT_NOQUOTES,$encoding);
$keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);
$content = array(
'title'=>$title,
'description'=>$body,
'mt_allow_comments'=>0, // 1 to allow comments
'mt_allow_pings'=>0, // 1 to allow trackbacks
'post_type'=>'post',
'mt_keywords'=>$keywords,
'categories'=>array($category)
);
$params = array(0,$username,$password,$content,true);
$request = xmlrpc_encode_request('metaWeblog.newPost',$params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, $rpcurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$results = curl_exec($ch);
curl_close($ch);
return $results;
?>
Wenig Code, großer Effekt
<?php
ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
?>
Eines meiner Lieblingsscripte für php,curl und twitter. Ideal zur Serverüberwachung,für Werbung und regelmäßige News! ( Besucht mal @michaelp08 )
<?php
// Set username and password
$username = 'username';
$password = 'password';
// The message you want to send
$message = 'is twittering from php using curl';
// The twitter API address
$url = 'http://twitter.com/statuses/update.xml';
// Alternative JSON version
// $url = 'http://twitter.com/statuses/update.json';
// Set up and execute the curl process
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
// check for success or failure
if (empty($buffer)) {
echo 'message';
} else {
echo 'success';
}
?>
Wie die Ausgabe und die Leistung dieses Server im Moment aussieht könnt ihr übrigens hier sehen
<?php error_reporting(E_ALL | E_STRICT);
// Initialize cURL with given url
$url = 'http://download.bethere.co.uk/images/61859740_3c0c5dbc30_o.jpg';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Sitepoint Examples (thread 581410; http://www.sitepoint.com/forums/showthread.php?t=581410)');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
set_time_limit(65);
$execute = curl_exec($ch);
$info = curl_getinfo($ch);
// Time spent downloading, I think
$time = $info['total_time']
- $info['namelookup_time']
- $info['connect_time']
- $info['pretransfer_time']
- $info['starttransfer_time']
- $info['redirect_time'];
// Echo friendly messages
header('Content-Type: text/plain');
printf("Downloaded %d bytes in %0.4f seconds.\n", $info['size_download'], $time);
printf("Which is %0.4f mbps\n", $info['size_download'] * 8 / $time / 1024 / 1024);
printf("CURL said %0.4f mbps\n", $info['speed_download'] * 8 / 1024 / 1024);
echo "\n\ncurl_getinfo() said:\n", str_repeat('-', 31 + strlen($url)), "\n";
foreach ($info as $label => $value)
{
printf("%-30s %s\n", $label, $value);
}
?>
Alle der vorgestellten Codes lassen sich natürlich auch in C++ und anderen Programmiersprachen anwenden! Wie das geht zeige ich die Tage :)
[...] Dieser Eintrag wurde auf Twitter von Michael Plas erwähnt. Michael Plas sagte: Neuer Artikel: 5 tolle Sachen die man mit cURL anstellen kann http://bit.ly/axEren [...]
Also der Twitter-Code funktioniert leider bei mir nicht
Habe die Sachen auf dem Home-Server, und es kommt folgende Fehlermeldung:
Fatal error: Call to undefined function curl_init() in I:\xampplite\htdocs\twitter.php on line 18
Wäre eigentlich sehr praktisch, wenn man darum ein kleines Formular entwerfen könnte, mit einem Feld für die Nachricht oder so…
Grüße, Lukas
Hey Lukas
XamppLite ( xampp standart glaub ich auch nicht ) hat kein cURL im Paket dabei, dies müsste manuell nachinstalliert werden :/
Ich weiß deine PHP-Kenntnisse sind nicht so das wahre, aber wenn du möchtest kann ich dir nen Formular dazubauen
Hallo,
habe auch folgendes Problem:
Fatal error: Call to undefined function curl_init() in /var/www/web0/html/twitter/twitter.validate.php on line 30
Seite: http://www.twitter-success.de (beim Login) Auf einem Testserver (anderer Provider) gehts. Warum nicht bei Alfahosting??
Sieht so aus als wäre bei alfahosting curl nicht aktiviert -> würde mal den support anschreiben
Die Berechnung für die Zeit bei Punkt 5, wie lange der Download gebraucht hat stimmt nicht. Ich habe vor einigen Tagen bei einem DNS-Problem folgende Daten:
3.024706 (total_time)
0.000027 (namelookup_time)
2.990970 (connect_time)
2.990975 (pretransfer_time)
3.024685 (starttransfer_time)
0.000000 (redirect_time)
Dabei wäre dann eine Dauer von -5.981951 Sekunden bei rausgekommen. Wäre natürlich super, wenn der Download bereits fertig wäre, bevor ich ihn gestartet hätte, aber wir sind hier nicht bei Minority Report
Achso, das Beispiel für Twitter sollte nicht mehr funktionieren, da Twitter die Authentifizierung auf OAuth umgestellt hat. Dafür ist dann etwas mehr Code nötig.
Vielen Dank für die Hinweise =)
Werde mal wenn ich Zeit habe neue Codes veröffentlichen
We do a qualitative [url=http://corvallisbuilder.com/]house walls[/url]
Surprising time in here; I forget to do my other activity because of your wonderful site. It doesn’t matter with me, because it is worthed and I will learn new knowledge, hope progressively I can meet with your speech. Linguists and educationalists (in my school) had conflicted and debated in several subject, I got the correction when I read the full article here. The positive effects of debatable discussion in my school are great brain for future time (for me and for my friends). Many subjects and topics with great confusing material in my school, but I have initiation step that your site has better correct conclusion. The above discussion in Linguists and educationalists is great. I’ve used several techniques for my research, for example online comparison. Would you mind if I make citation for my future project? (Of course I will tell you later, once I got the project plan in my hand). Thanks for your attention in reading my comments; you can shot me in my comment details to execute this project, so you can to be as a great part in my project.
Wonderful tips. I was reading through the write-up and I was like “what about content?” lol. Surely I consider articles is generally an overlooked aspect and as you explained is absolutely king. Not only does it drive targeted visitors but it produces fantastic links! Good article on the nuts and bolts of SEO.