1

I found a script in Web Designer magazine that enables you to gather Album Data from a Facebook Fan Page, and put it on your site.

The script utilizes PHP's file_get_contents() function, which works great on my personal server, but is not allowed on the Network Solutions hosting.

In looking through their documentation, they recommended that you use a cURL session to gather the data. I have never used cURL sessions before, and so this is something of a mystery to me. Any help would be appreciated.

The code I "was" using looked like this:

<?php
    $FBid = '239319006081415';
    $FBpage = file_get_contents('https://graph.facebook.com/'.$FBid.'/albums');
    $photoData = json_decode($FBpage);

    $albumID = $photoData->data[0]->id;
$albumURL = "https://graph.facebook.com/".$albumID."/photos";

    $rawAlbumData = file_get_contents("https://graph.facebook.com/".$albumID."/photos");
$photoData2 = json_decode($rawAlbumData);

    $a = 0;

foreach($photoData2->data as $data) {
        $photoArray[$a]["source"] = $data->source;
    $photoArray[$a]["width"] = $data->width;
    $photoArray[$a]["height"] = $data->height;
    $a++;
}
?>

The code that I am attempting to use now looks like this:

<?php
    $FBid = '239319006081415';
$FBUrl = "https://graph.facebook.com/".$FBid."/albums";

    $ch = curl_init($FBUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$contents = curl_exec($ch);
curl_close($ch);
$photoData = json_decode($contents);
?>

When I try to echo or manipulate the contents of $photoData however, it's clear that it is empty.

Any thoughts?

John Hubler
  • 877
  • 1
  • 11
  • 27
  • Change hosting. They are clueless. There is no reason to disable `allow_url_fopen` but allow cURL. – Gordon Sep 26 '11 at 14:54
  • 1
    I hear ya. I am going to suggest changing the host. I've only had problems with these guys thus far. However, if the client is unwilling to change hosts - my hands are tied. – John Hubler Sep 26 '11 at 14:57
  • I have a FBJS (client-side) only album loader that can load photos from a public album. Might be more useful: https://github.com/davidosomething/Facebook-OpenGraph-API-Album-Loader – davidosomething Sep 26 '11 at 15:01
  • This looks like it might be exactly what I am looking for! Thank you! – John Hubler Sep 26 '11 at 15:04

3 Answers3

0

Use jquery get Json instead This tips is from FB Album downloader GreaseMonkey script

Ana
  • 1
0

Try removing curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); I'm not exactly sure what that does but I'm not using it and my code otherwise looks very similar. I'd also use:

json_decode($contents,true); This should put the results in an array instead of an object. I've had better luck with this approach.

Put it in the works for me category.

Dustin Nielson
  • 1,264
  • 1
  • 8
  • 8
0

Try this it could work

$ch = curl_init($FBUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$contents = curl_exec($ch);
$pageData = json_decode($contents);
//object to array
$objtoarr = get_object_vars($pageData);
curl_close($ch);
Sam Arul Raj T
  • 1,752
  • 17
  • 23