3

I'm trying to use the Facebook api to run an fql query. I set everything up in PHP here is how the code looks:

  $app_id = 'APP_ID';
  $app_secret = 'APP_secret';
  $my_url = "url.com/facebook.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) ;
    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;
  $access_token = file_get_contents($token_url);


  // Run fql query
  $fql_query_url = 'FQL_Query';
  $fql_query_result = file_get_contents($fql_query_url);
  $fql_query_obj = json_decode($fql_query_result, true);

Everything worked fine using the code above, but recently I decided to change my URL structure and instead of accessing the page via url.com/facebook.php I would like to access it via url.com/#facebook.

When I made this change to the $my_url variable I received the following errors.

[function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request

Any ideas? Thanks!

user1210772
  • 71
  • 2
  • 3
  • 9
  • 1
    I'm voting to close this question as off-topic because FQL was removed years ago and the Community bot bumped it. – ceejayoz Mar 06 '19 at 01:18

2 Answers2

0

I solved it in XAMPP by adding extension=php_openssl.dll in xampp/php/php.ini file. in some versions of XAMPP this line is commented like ;extension=php_openssl.dll, so just uncomment it and restart apache.

Ritesh Chandora
  • 8,382
  • 5
  • 21
  • 38
0

Well, Let's start with the facebook application settings. In the app settings you define the "Canvas URL" and if you decide to change that, then you need to change it not only in your code but also in the application settings in the developer app.

Another thing is that if facebook called your page with a url, then you must use the exact same url in the redirect_uri parameter when going for authentication, it's in the documentation (http://developers.facebook.com/docs/authentication/). This is what they write about the redirect_uri:

The redirect_uri must be in the path of the Site URL you specify in Website section of the Summary tab in the Developer App. If it is the root of the domain, it should end with a trailing slash. Note, your redirect_uri can not be a redirector.

and

In order to authenticate your app, you must pass the authorization code and your app secret to the Graph API token endpoint - along with the exact same redirect_uri used above - at https://graph.facebook.com/oauth/access_token

Now, your decision to change the url to have a hash in it (#) is not a good one. This part of the url is not meant for what you're trying to use it for. Just google "hash part in url" and read a bit.

Nitzan Tomer
  • 155,636
  • 47
  • 315
  • 299
  • Thanks for the response. I need to use the hash in my URL as I cannot have the user refresh the page as some of the data I'm storing would be lost. I tried all the above with no luck. Does Facebook allow you to use a hash in the URL? – user1210772 Feb 17 '12 at 21:12
  • I came across some issues in the last days, showing that the use of the file-get-contents method causes problems... Check out: http://stackoverflow.com/questions/6903240/getting-404-error-from-facebook-graph-api and http://stackoverflow.com/questions/9333139/facebook-auth-with-high-traffic-sites-empty-access-tokens-empty-me#comment11778884_9333139. Besides that issue, I strongly advise you not to use the hash for server issues. It should be used for client side functionality only. – Nitzan Tomer Feb 17 '12 at 22:38
  • Thanks for the response. I went over the links you send me and am still a little lost. – user1210772 Feb 18 '12 at 03:25
  • I'm nt promising anything, but looks like the file_get_contents is not the best of choice. In the first link I sent they show how to replace the use of this method with another, alternative method: curl. Try to use that and see if it solves the problem for you. – Nitzan Tomer Feb 18 '12 at 10:17