-3

I am a novice and though I manage to get things done, this issue is out of my reach.

Issue related to Facebook

https://graph.facebook.com/211255505590483/albums?fields=id

The above link displays the list of albums of a Facebook page. I want to extract all the "id" and put them in a dropdown list. e.g.: <option value="123456789">123456789</option>


This section added after response by @Mathieu to remove confusion:

Question: I need help to extract just the Album IDs which I can use for the dropdown list. I have tried "preg_match" but I am unable to isolate and get just the Album IDs. I am getting the entire content either as a single line or with line breaks and that includes "created_time" part also.


I already have a PHP script which can display all the photos of an album (of a Facebook Page) when I directly put the album "id" in it.

My 'plan one' is that whenever a visitor comes to my website, my page will fetch the list of album "id" and the photos can be viewed.

My 'plan two' is that the page can use a cron to fetch the list of album "id" once a day and store in a database and this will prevent multiple calls to Facebook.

I feel that since the list of album "id" is available through the above link, there would Not be any need for AccessToken, Secret, etc.

Vinayy
  • 11
  • 4
  • I have mentioned, and I repeat: I want to extract all the "id" and put them in a dropdown list. e.g.: [code][/code] – Vinayy Aug 10 '12 at 12:48
  • @Vinayy We are not trying to be annoying, but this is not a question either. You seem to have every information do get the IDs and build a dropdown list. Do you have a specific issue we can help you with? – Tchoupi Aug 10 '12 at 13:12
  • @MathieuImbert: I apologize for making it confusing. I need help to extract just the Album IDs which I can use for the dropdown list. I have tried "preg_match" but I am unable to isolate and get just the Album IDs. I am getting the entire content either as a single line or with line breaks and that includes "created_time" part also. – Vinayy Aug 10 '12 at 15:52
  • Facebook data is encoded with JSON. Use `json_decode()` to decode it. – Tchoupi Aug 10 '12 at 16:40

1 Answers1

1

Done

This script works only for a Facebook page to display all the Albums. You would need a separate script to show all the photos of any particular album.

Edit: I have improved upon the solution. The script now gives the Album IDs in a dropdown box, The Album Name and Album Creation Date.

<?php

$facebook_page_owner = "211255505590483";

$string = file_get_contents('https://graph.facebook.com/'.$facebook_page_owner.'/albums?fields=id,name,cover_photo');
$jdata = json_decode($string);
$albumcount = count($jdata->data);

echo "There are ".$albumcount." Albums in this Facebook page.<br /><br />";

echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">";

echo "<select id=\"facebookalbumid\" name=\"facebookalbumid\">";

    $facebookalbumid = $_POST['facebookalbumid'];
    $i=0;
    while($i<=($albumcount-1))
        {
        $selected = ($jdata->data[$i]->id == $facebookalbumid) ? "selected='selected'" : "";
            if ($facebookalbumid == "") {
            $facebookalbumid = $jdata->data[$i]->id;
            }
        echo "<option value=\"".$jdata->data[$i]->id."\" $selected>".$jdata->data[$i]->id."</option>";
        $i++;
    }

echo "</select>";

echo " <input type=\"submit\" value=\"View Album\"></form><br />";


$string2 = file_get_contents('https://graph.facebook.com/fql?q=SELECT%20name,%20created%20FROM%20album%20WHERE%20owner='.$facebook_page_owner.'%20and%20object_id='.$facebookalbumid.'');
$adata = json_decode($string2);
$facebookalbumname = $adata->data[0]->name;
$albumdate = $adata->data[0]->created;
$facebookalbumdate = date("d-M-Y", $albumdate);

echo $facebookalbumname."<br />";
echo $facebookalbumdate."<br />";

?>
Vinayy
  • 11
  • 4