doufang6268 2013-06-13 12:23
浏览 31

如果到期,如何获取访问令牌

i have made an app which helps a user to post photos directly to a fb page from website.

the problem i am facing now is that if the access token expires i have to put new access token every time. i need a way to get a users access token automatically. is there any way? This is the code

    <?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once 'library/facebook.php';
$facebook = new Facebook(array(
    'appId'  => 'My_app_ID',
    'secret' => 'My_App_secret',
    'fileUpload' => true
));


#It can be found at https://developers.facebook.com/tools/access_token/
#Change to your token.
$access_token = 'CAAHkfWZB9T84BACm0LqdF1V5BFcppXZCHM7mrRxy9g8SRvw6Wz2RFZBMnYsdgsg413fIE5mpZChgYvz0DiJGGDUsVn8CKkZAFWvm6GHvcGw2xeD8EKH0D7MdkWrdNvD08oXabjzyfPsSTZCxfj1qPg40z4rFUQs8zSOIZD';

$params = array('access_token' => $access_token);

#The id of the fanpage
$fanpage = '232241216922182';

#The id of the album
$album_id ='281594988653471';

//here Wa33D94 is the id of the admin of the page where the photos will be uploaded
$accounts = $facebook->api('/Wa33D94/accounts', 'GET', $params);

foreach($accounts['data'] as $account) {
    if( $account['id'] == $fanpage || $account['name'] == $fanpage ){
        $fanpage_token = $account['access_token'];
    }
}


$valid_files = array('image/jpeg', 'image/png', 'image/gif');

if(isset($_FILES) && !empty($_FILES)){
    if( !in_array($_FILES['pic']['type'], $valid_files ) ){
        echo 'Only jpg, png and gif image types are supported!';
    }else{
        $img = realpath($_FILES["pic"]["tmp_name"]);

        $args = array(
            'message' => 'This photo was uploaded via clixbox.net',
            'image' => '@' . $img,
            'aid' => $album_id,
            'no_story' => 1,
            'access_token' => $fanpage_token
        );

        $photo = $facebook->api($album_id . '/photos', 'post', $args);
        if( is_array( $photo ) && !empty( $photo['id'] ) ){
            echo '<p><a target="_blank" href="http://www.facebook.com/photo.php?fbid='.$photo['id'].'">Click here to watch this photo on Facebook.</a></p>';
        }
    }
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Upload pictures to facebook cia Clixbox.net</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
html{
    font-family: "lucida grande",tahoma,verdana,arial,sans-serif;
}
.main{
    width:400px;
    margin:auto;
    border:2px solid #0066CC;
    color:#3B5998;
    padding:20px;
    font-size: 11px;
    -moz-border-radius: 4px 4px 4px 4px;
    border-radius: 4px 4px 4px 4px;
    -moz-box-shadow: 1px 1px 0 #d5d5d5;
    background: none repeat scroll 0 0 #F2F2F2;
}
.text{
    color: #777777;
    border: 1px solid #BDC7D8;
    font-size: 11px;
    height: 15px;
}
.post_but {
    background: none repeat scroll 0 0 #EEEEEE;
    border-color: #999999 #999999 #888888;
    border-style: solid;
    border-width: 1px;
    color: #333333;
    cursor: pointer;
    display: inline-block;
    font-size: 11px;
    font-weight: bold;
    padding: 2px 6px;
    text-align: center;
    text-decoration: none;
}
a{
    color:#3B5998;
}
</style>
</head>

<body>

    <div class="main">
        <p>Select a photo to upload on Facebook Fan Page</p>
        <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
        <p>Select the image: <input type="file" name="pic" /></p>
        <p><input class="post_but" type="submit" value="Upload to my album" /></p>
        </form>
    </div>

</body>
</html>
  • 写回答

1条回答 默认 最新

  • douzi6060 2013-06-13 12:29
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探