开发者

Unable to retrieve Facebook Wall Posts

Using Facebook Graph API and my app credentials I am able to retrieve a valid token:

171372936213670|xxxxxxxxxxxxxxxxxx-650901429|x_xxxxxxxxxxxxxxx-xxxxxxxx

The code I use to retrieve Wall Posts:

function getFbWallPosts($user, $limit=5) {
    $ci =& get_instance();
    $token = $ci->facebook->getAccessToken();
    $param = array(
        'access_token' => $token, 
        'limit' => $limit,
        );
    $posts = $ci->facebook->api("$user/feed", 'GET', $param);

    return $posts; 
}

The function always returns an empty jSON result:

{"data":[]}

Also tested directly accessing Wall Posts using cURL:

function fbrequest($url) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    curl_close($ch);

    return $output;
}

...to no avail.

EDIT: Also tried using file_get_contents but it also returns empty jSON:

function fbreq开发者_如何学JAVAuest($url) {
   $output = file_get_contents($url);
   return $output;
}

Tried pasting the request string directly on my browser (without a user logged in to Facebook):

https://graph.facebook.com/AValidFacebookUsername/feed?access_token=171372936213670|xxxxxxxxxxxxxxxxxx-650901429|x_xxxxxxxxxxxxxxx-xxxxxxxx

...successfully returns a jSON string with all the posts

Any ideas guys?


Try...

function curl($url){
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    $content = curl_exec($curl);
    curl_close($curl);
    return $content;
}

If no luck, maybe Apache is not compiled with SSL support.


I just found out that there is nothing wrong with the codes I'm writing. The problem is with how I interpreted the process and, eventually, the result. There are pre-requisites on accessing other user's data on FB and in case of group pages, one of them is that the user requesting the data MUST BE A FAN OF THAT GROUP.

Silly me...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜