2013-02-17 25 views
13

FacebookのIDを参照して、Facebookのすべての投稿を取得したいと考えています。私はこれを試しました:facebook graph apiでグループの投稿をすべて入手する方法

https://graph.facebook.com/".$group_id."/feed?time_format=U&".$authToken 

私は特定の投稿を与えます。可能であれば、ページングURLではなく、単一のURLですべての投稿を取得したい。ただし、ページングトークンにはページングトークンが含まれています。

https://graph.facebook.com/55259308085/feed?limit=500&access_token=ACCESS_TOKEN&until=1298025645&__paging_token=55259308085_10150259582898086 

ページングトークンとは何ですか?

正しいパスに移動してください。 ありがとうございます。

答えて

15
set_time_limit(99999999); 
ini_set('memory_limit', "9999M"); 

function fetchUrl($url) { 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 40); 

    $data = curl_exec($ch); 
    curl_close($ch); 

    return $data; 
} 

$url_array = array(); 

function recurse_it($url, $c) { 
    global $url_array; 
    $feeds   = fetchUrl($url); 
    $feed_data_obj = json_decode($feeds, true); 
    if (!empty($feed_data_obj['data'])) { 
     $next_url  = $feed_data_obj['paging']['next']; 
     $url_array[$c] = $next_url; 
     recurse_it($next_url, $c + 1); 
    } 
    return $url_array; 
} 

$url = "https://graph.facebook.com/55259308085/groups?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; 
$arr = recurse_it($url, 0); 
print_r($arr); 


必要に応じて、より詳しい説明ができます。別の簡単な解決策のための

+0

OAuthを使用してアクセストークンを取得する必要がある/ – weaveoftheride

+2

上記のコードをPythonで投稿する機会はありますか?それは素晴らしいだろう! – avi

9

は、PHPでこれを試してみてください:

$response = file_get_contents("https://graph.facebook.com/$group_id/feed?limit=1000&access_token=$access_token"); 

それは1000のポストの限界にあなたのページを与えるでしょう。 PHPの連想配列にJSONレスポンスを変換します

$array = json_decode($response, true); 
// Do your own stuff with $array ... 

次のページを介して取得:$array['data']が応答で空として出てくるまで

$response = file_get_contents($array['paging']['next']); 

は、ループ内でこれを試してみてください。


まで - これはポスト(すなわち、表示された後に行わのみポスト)フェッチされるべきまでの時点を指定するために使用されるUNIX時間の整数です。 $arr私は改ページのすべての内容をループへのforeachを使用するすべての利用可能なページ付けリンクのアレイである

+0

こんにちはniteshのTHXが...しかし、別の方法を考え出したアイブ... –

+0

@Nilesh:私はあなたの代わりにjson_encode' 'の**' json_decode'を**入力したいと思います。 :) – Sk8erPeter

+0

@ Sk8erPeter:私の悪い。編集にも感謝します。 :) – Nilesh

1
$url_array=array(); 
    $url="https://graph.facebook.com/v2.2/".$fbpageid."/feed?access_token=".$access_token."&limit=250&fields=full_picture,picture,id,message,name,caption,description,updated_time,link,icon,from,privacy,type,status_type,application,object_id,story,story_tags,actions"; 

    function recurse_it($url,$c) 
    { 
     $feeds=file_get_contents($url); 
     $feed_data_obj=json_decode($feeds,true); 
     while(!empty($feed_data_obj['data'])) 
     { 
      $next_url  = $feed_data_obj['paging']['next']; 
      $url_array[$c] = $next_url; 
      $feeds=file_get_contents($next_url); 
      $feed_data_obj=json_decode($feeds,true); 
      $c=$c+1; 
     } 
     return $url_array; 
    } 
    $final_result=recurse_it($url,0); 
関連する問題