代码之家  ›  专栏  ›  技术社区  ›  M0ns1f

PHP-仅使用Facebook图形从Facebook页面获取帖子数据

  •  0
  • M0ns1f  · 技术社区  · 8 年前

    有没有办法 脸谱网 php

    我需要在没有 或者 Facebook API 脸书图表 Facebook应用程序

    1 回复  |  直到 8 年前
        1
  •  1
  •   M0ns1f    8 年前

    我找到了解决方案

    <?php
    error_reporting(0);
    /*xxxxclient_idxxx='your clientid'*/
    /*xxxxxxclient_secretxxxx='your client_secret'*/
    //Replace "YOUR-PAGE-NAME" with your page name.
    $access_str = file_get_contents('https://graph.facebook.com/oauth/access_token?client_id=xxxxclient_idxxx&client_secret=xxxxxxclient_secretxxxx&grant_type=client_credentials');
    $tokenarr = str_replace('"','',$access_str);
    $tokenarray = explode(":",str_replace(',',':', $tokenarr));
    var_dump($tokenarray);  //Request the public posts. 
    $json_str = file_get_contents('https://graph.facebook.com/YOUR-PAGE-NAME/feed??fields=attachments&fields=attachments&access_token='.$tokenarray[1]);
    
    //decode json string into array
    
    $data = json_decode($json_str);
    
    foreach ($data as $posts) {
        foreach($posts as $post){
        $postit = (array) json_decode(json_encode($post), True);
        foreach ($postit as $getit) {
        echo '<p>' .$getit['data'][0]['description'].'</p>';
        echo '<img src="'.$getit['data'][0]['media']['image']['src'].'" />';
        echo "</br>-----------</br>";
            }
    
        }
    }
    
    ?>
    

    此脚本获取状态文本和图像