I upgraded to FQL to Graph API - am I using it correctly?
Asked Answered
N

2

10

I used the FQL until a few days ago to retrieve Facebook data, but I noticed that it will be discontinued in about 1 year so I upgraded to Graph API. But am I using it correctly? Will this method work still next year? I am still using a

facebook.php, base_facebook.php and fb_ca_chain_bundle.crt

from 2011 but then again I only need these functions.

Here's my code, thanks for any advice you can give me :)

        function get_content($URL){
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                  curl_setopt($ch, CURLOPT_URL, $URL);
                  $data = curl_exec($ch);
                  curl_close($ch);
                  return $data;
        }

        $access_token =  $facebook->getAccessToken();

        $data = get_content("https://graph.facebook.com/" . $facebook_id . "/?fields=name,first_name,last_name,email&access_token=".$access_token);
        $data_array = json_decode($data, true);

        $new_array = array(
            "uid" => $data_array['id'],
            "name" => $data_array['name'],
            "first_name" => $data_array['first_name'],
            "last_name" => $data_array['last_name'],
            "email" => $data_array['email']
        );
Nettles answered 1/8, 2015 at 10:8 Comment(0)
D
3

That looks perfectly correct!

The only improvement to that code would be to add the API version number to the call.

So, use https://graph.facebook.com/v2.4/

$data = get_content("https://graph.facebook.com/v2.4/**" . $facebook_id . "/?fields=name,first_name,last_name,email&access_token=".$access_token);

That way, you'll not be affected by any changes until at least July 2017!

Deryl answered 11/8, 2015 at 18:12 Comment(0)
M
2

You might want to catch any connection or HTTP errors returned. Some of the HTTP errors are documented here.

You can use the Graph API explorer for making test API calls and verifying your requests.

Meditate answered 13/8, 2015 at 11:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.