====== PHP - Curl to Facebook ====== ===== To login to Facebook using curl. ===== $login_email = 'email'; $login_pass = 'password'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://www.facebook.com/login.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_COOKIEJAR, "cookies.txt"); curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 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_setopt($ch, CURLOPT_REFERER, "http://www.facebook.com"); $page = curl_exec($ch) or die(curl_error($ch)); echo $page; The cookie file 'cookies.txt' exists, and has 644 permissions. An alternative approach is to disable cookies using: curl_setopt($ch, CURLOPT_COOKIESESSION, false); ===== Post to a Facebook User's Wall ===== $attachment = array( 'access_token' => $token, 'message' => $msg, 'name' => $title, 'link' => $uri, 'description' => $desc, 'picture'=>$pic, 'actions' => json_encode(array('name' => $action_name,'link' => $action_link)) ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/fbnameorid/feed'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // To suppress the curl output. $result = curl_exec($ch); curl_close ($ch); ===== Upload a picture to Facebook using Curl ===== To upload a picture from your server, change the request url to: **graph.facebook.com/fbnameorid/photos** and add an array item called 'file' with value '@'. [path to file]