this is what i use:
$facebook = new Facebook(array( 'appId' => FACEBOOK_APP_ID, 'secret' => FACEBOOK_SECRET, 'cookie' => true, 'fileUpload' => true, )); $user = $facebook->getUser(); // Get the UID of the connected user, or 0 if the Facebook user is not connected. $facebook->setFileUploadSupport(true); if($user == 0) { // If the user is not connected to your application, redirect the user to authentication page /** * Get a Login URL for use with redirects. By default, full page redirect is * assumed. If you are using the generated URL with a window.open() call in * JavaScript, you can pass in display=popup as part of the $params. * * The parameters: * - redirect_uri: the url to go to after a successful login * - scope: comma separated list of requested extended perms */ $login_url = $facebook->getLoginUrl($params = array('redirect_uri' => REDIRECT_URI,'scope' => PERMISSIONS_REQUIRED)); echo ("<script> top.location.href='".$login_url."'</script>"); } else { // if the user is already connected, then fetch access_token and user information or show some content to logged in user. try { $access_token = $facebook->getAccessToken(); // Gives you current user access_token $user = $facebook->api('/me'); // Gets User information based on permissions the user has granted to your application. } catch(FacebookApiException $e){ $results = $e->getResult(); // Print results if you want to debug. } } $img = './upload/'.$image_path; $args = array( 'message' => 'Some Message', 'access_token'=>urlencode($access_token), ); $args[basename($img)] = '@'.realpath($img); $ch = curl_init(); $url = 'https://graph.facebook.com/me/photos'; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $args); $data = curl_exec($ch); $response = json_decode($data,true);
source share