开发者

Using CURL with FQL in a simple PHP social media class

开发者 https://www.devze.com 2023-03-13 21:06 出处:网络
I\'m building a simple PHP class that will allows you to enter your twitter usename, number of tweets to load, facebook id, number of statuses to load, and access token and then retrieves your user da

I'm building a simple PHP class that will allows you to enter your twitter usename, number of tweets to load, facebook id, number of statuses to load, and access token and then retrieves your user data (name, profile pic, etc.) and the specified number of tweets/statuses.

I'm retrieving the data as JSON by calling a URL using cURL and using PHP's built in json_decode() function to parse it into an object for me.

My problem is this - I can retrieve all the twitter data perfectly fine by passing the username to the correct url (e.g. http://twitter.com/users/user.json) but all of the facebook data is returning NULL. I think I know the problem - I am using FQL so am calling URLs like:

https://api.facebook.com/method/fql.query?format=json&access_token=####&query=SELECT first_name,middle_name,last_name FROM user WHERE uid = #### LIMIT 1";

which seems to then redirect you to the built file (whereas twitter is linked di开发者_开发百科rectly to the correct file).

Does anybody know how I can make this work? I would prefer to use FQL as I've got my head around it a bit more but if it's not possible it's not too big a deal for me to change.

I can provide any other details you need


Your syntax looks perfectly fine, so chances are that there might be an issue with the way you are passing in the access token.

I just look a look at some code I had written, and I'm passing in app ID and app secret, not the access token. I'm not sure if makes a difference or not since I wrote that code a while ago, but it might.

If you are using PHP, you can use the PHP SDK for Facebook. This will let you write slightly less verbose code which will be easier to maintain. You can find it here: http://developers.facebook.com/docs/sdks/

Using it I write this to call FQL queries:

    $facebook = new Facebook(array(
        'appId'  => $fb_config["app_id"],
        'secret' => $fb_config["secret"],           
        'cookie' => true,));

    $params = array( 
        'queries' => $queries,
        'method' => "fql.multiquery"
    );

Depending on what you are trying to do you can also use the Graph API to get data. In the example you are using the Graph API might be simpler. But if you are trying to get complicated data then FQL would be better.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号