duandun3178 2013-02-15 11:17
浏览 175

(PHP)在未经许可的情况下抓取AccessToken和feed。 (几分)

I'm beginning a blog and I wanted to make a 'FacebookStatusApp' for the blog. All it has to do is get my latest status and get request it to my translator page. I can get my latest feed but the problem is the accesstoken. I found a way to keep refreshing my access_token every 9 minutes. It's a site called:

https://mywebcron.com/

This site will call your url every X minutes. I chose 9 minutes.

My renew code is pretty simple:

<?php
$file = file_get_contents("fbat.txt");
$token = $file;

$token_url = "https://graph.facebook.com/oauth/access_token?client_id=100000280644272&client_secret=secret&grant_type=fb_exchange_token&fb_exchange_token=".$token;

$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_URL, $token_url);
$contents = curl_exec($c);
$err  = curl_getinfo($c,CURLINFO_HTTP_CODE);
curl_close($c);

$paramsfb = null;
//parse_str($contents, $paramsfb);
echo $contents;
?>

"Fbat.txt" contains the current AccessToken.

But I need a client_secret for my account. And I can't get a AccessToken for my facebook account :/

So my solution was creating a new app using MY ClientID and HIS ClientSecret with the 'GRAPH EXPLORER' to generate a access_token.

So my question is: How can I get MY latest status AND MY access_token. ?

If there is a good alternative (Ex. Using an APP) I could do that too.

Well, I hope you understand my question :P

  • 写回答

1条回答 默认 最新

  • dou1908 2013-02-15 14:02
    关注

    First of all, your feed needs to be public. The below code should do the rest:

    function fb_setup(){
    
        $app_id = 'APP_ID';
        $app_secret = 'APP_SECRET';
    
        $response = file_get_contents('https://graph.facebook.com/oauth/access_token?type=client_cred&client_id='.$app_id.'&client_secret='.$app_secret);
    
        $token = str_replace('access_token=', '', $response);
    
        $node = "PAGE_ID(if not a page just use 'me')";
        $fields = array();
        $fields[] = 'feed';
        $fields[] = 'likes';
    
        $response = file_get_contents('https://graph.facebook.com/'.$node.'?fields='.implode(',', $fields).'&access_token='.$token.'');
    
        $arr = json_decode($response);
    
        $data['node'] = $node;
        $data['arr'] = $arr;
    
        return $data;
    
    }
    function last_post(){
    
        $ret = fb_setup();
        $arr = $ret['arr'];
        $node = $ret['node'];
    
        $feed = $arr->feed->data;
    
        $ret = "";
        $ret .= "<div id='last-fb-post'>";
        $item = $feed[0];
    
        $message = str_replace("
    ","</p><p>",$item->message);
        $likes = (!$item->likes->count) ? '0' : $item->likes->count;
        $coms = $item->comments->count;
        $ex_id = explode('_',$item->id);
        $id = $ex_id[1];
    
        $href = 'http://www.facebook.com/permalink.php?story_fbid='.$id.'&id='.$node;
    
        $ret .= '<a class="title" target="_blank" href="'.$href.'">Last Update: <u>' . date("F j, Y",strtotime($item->created_time)) . '</u></a>';
        if($item->type == 'photo'){
            $ret .= '<div class="fb_img"><a target="_blank" href="'.$href.'"><img src="'.$item->picture.'"/></a></div>';
        }
        $ret .= "<p class=\"msg\">";
        $ret .= $message;
        $ret .= "</p>";
        $ret .= "<p class='likes'><a htarget=\"_blank\" href=\"$href\">$likes</p>";
    
    
    
        $ret .= "</div>";
    
        return $ret;
    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题