views:

74

answers:

0

Hi

I'm trying to upload www hosted (e.g. http://www.google.se/intl/en_com/images/srpr/logo1w.png) files to a facebook album.

Creating an album works just fine, but I don't seem to uploading any photos. I'm using the facebook php-sdk ( http://github.com/facebook/php-sdk/ ) and the examples I already tried are:

http://stackoverflow.com/questions/2718610/upload-photo-to-album/2728275#2728275

http://stackoverflow.com/questions/2964410/how-can-i-upload-photos-to-album-using-facebook-graph-api/3006901#3006901

I'm guessing CURL uploads perhaps only can manage locally stored files and not web hosted ones.

Here's my code:

      /*
  Try 1:

  $data = array();
  $data['message'] = $attachment->post_title;
  $data['file'] = $attachment->guid;

  try {
   $photo = $facebook->api('/' . $album['id'] . '/photos?access_token=' . $session['access_token'], 'post', $data);
  } catch (FacebookApiException $e) {
   error_log($e);
  }
  */

  // Try 2:
  //upload photo
  $file = $attachment->guid;
  $args = array(
   'message' => 'Photo from application',
  );
  $args[basename($file)] = '@' . realpath(file_get_contents($file));

  $ch = curl_init();
  $url = 'https://graph.facebook.com/' . $album['id'] . '/photos?access_token=' . $session['access_token'];
  curl_setopt($ch, CURLOPT_URL, $url);
  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);
  //returns the photo id
  print_r(json_decode($data,true));

...where attachment->guid contains the photo url.

I'm pretty much stuck right now...