Click here to Skip to main content
15,068,929 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

I'm trying to execute this code in Facebook developer
upload.php
PHP
<?php
  // Remember to copy files from the SDK's src/ directory to a
  // directory in your application on the server, such as php-sdk/
  require_once('php-sdk/facebook.php');

  $config = array(
    'appId' => 'appId',
    'secret' => 'secret',
    'fileUpload' => true,
    'allowSignedRequest' => false // optional but should be set to false for non-canvas apps
  );

  $facebook = new Facebook($config);
  $user_id = $facebook->getUser();

  $photo = 'facebook_logo.jpg'; // Path to the photo on the local filesystem
  $message = 'Photo upload via the PHP SDK!';
?>
<html>
  <head></head>
  <body>
  <?php
    if($user_id) {

      // We have a user ID, so probably a logged in user.
      // If not, we'll get an exception, which we handle below.
      try {

        // Upload to a user's profile. The photo will be in the
        // first album in the profile. You can also upload to
        // a specific album by using /ALBUM_ID as the path 
		//'source' => new CURLFile($photo, 'image/png'),
        $ret_obj = $facebook->api('/me/photos', 'POST', array(
                                         'source' => $photo,
                                         'message' => $message,
                                         )
                                      );
        echo 'Photo ID: ' . $ret_obj['id'];
        echo '<a href="' . $facebook->getLogoutUrl() . '">logout</a>';
      } catch(FacebookApiException $e) {
        // If the user is logged out, you can have a 
        // user ID even though the access token is invalid.
        // In this case, we'll get an exception, so we'll
        // just ask the user to login again here.
        $login_url = $facebook->getLoginUrl( array(
                       'scope' => 'photo_upload'
                       )); 
        echo 'Please <a href="' . $login_url . '">login.</a>';
        error_log($e->getType());
        error_log($e->getMessage());
      }   
    } else {

      // No user, print a link for the user to login
      // To upload a photo to a user's wall, we need photo_upload  permission
      // We'll use the current URL as the redirect_uri, so we don't
      // need to specify it here.
      $login_url = $facebook->getLoginUrl( array( 'scope' => 'photo_upload') );
      echo 'Please <a href="' . $login_url . '">login.</a>';

    }
  ?>


When I clicked login (in facebook)
Error
App Not Setup: The developers of this app have not set up this app properly for Facebook Login.

I already try getting the code for getting user info and posting a link posted in Facebook developer and it works fine.

In my Facebook Developer Settings
App on Facebook
Canvas URL: http://localhost/sites/folder/
Canvas URL: https://localhost/sites/folder/
Website
Site URL: http://localhost/sites/folder/

And what does this means
To upload a photo to a user's wall, we need photo_upload permission
Can't find this in Settings.. Don't know if this permission is in Users Profile, If so where can i find it?
Posted
Updated 17-Mar-14 1:18am
v4

1 solution

Solve it
PHP
$ret_obj = $facebook->api('/me/photos', 'POST', array(
      'source' => '@' . realpath($photo),
      'message' => $message,
    )
);
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900