0

I am working on a small app that lets the user to select a photo from his facebook album preferably from profile or cover album.
I am using the following code. test url http://babysoftblog.com/megapicture/albums.php

<?php
  $app_id = 'XXXXX';
  $app_secret = 'XXXXX';
  $my_url = 'http://babysoftblog.com/megapicture/albums.php';

  $code = $_REQUEST["code"];

 // auth user
 if(empty($code)) {
    $dialog_url = 'https://www.facebook.com/dialog/oauth/?client_id='.$app_id.'&redirect_uri='.urlencode($my_url).'&scope=user_photos';
                   echo("<script>top.location.href='" . $dialog_url . "'</script>");
  }

  //get user access_token

              $token_url = 'https://graph.facebook.com/oauth/access_token?client_id='
                . $app_id . '&redirect_uri=' . urlencode($my_url) 
                . '&client_secret=' . $app_secret 
                . '&code=' . $code;
  try {
              $access_token = file_get_contents(@$token_url);
  }
   catch (Exception $e)
           { echo "OOPs look like something went wrong"; }

             //$fql_query_url = 'https://graph.facebook.com/'.'fql?q=SELECT+pid,src_small+FROM+photo+WHERE+aid+IN+(SELECT+aid+FROM+album+WHERE+owner=+me())&'.$access_token;

           try{
            $fql_query_url = 'https://graph.facebook.com/'.'fql?q=SELECT+aid,name+FROM+album+WHERE+owner=+me()&'.$access_token;
            $fql_query_result = file_get_contents($fql_query_url);
            $fql_query_obj = json_decode($fql_query_result, true);
           }
           catch (Exception $e)
           { echo "oops something went wrong"; }
?>

But with the above code when I refresh the page .. it gives exception, please see here http://babysoftblog.com/megapicture/albums.php and how I can directly select photos of profile and cover albums.

Please help me in this, thanks in advance.

1 Answers1

0

i saw you app and i think you have changed source of page . The error lies in query itself,

SELECT pid,src FROM photo WHERE aid =100001475149878_7668

this query should be written as

SELECT pid,src FROM photo WHERE aid ='100001475149878_7668';

or

SELECT pid,src FROM photo WHERE aid ="100001475149878_7668";

the error is because aid contains an _ which is part of a string so it should be enclosed in ' or " .