access_token-用于在粉丝页面相册中上传照片的脚本 [英] access_token - Script to upload photo in fan page album

查看:86
本文介绍了access_token-用于在粉丝页面相册中上传照片的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发要包含在页面"标签中的应用.在此应用中,用户将使用您的网络摄像头拍照,并将照片发送到我的粉丝页面中的一个特定相册.

I am developing an app to include in my page tab. In this app, the user will go take a picture with your webcam and the picture will sent to an especific album in my fan page.

我在这里找到了一个脚本:他工作得很好,但是我有一个问题,该脚本使用用户access_token上载图片,不需要所有用户都要求上载图片的权限,因为该脚本使用了我的管理员用户以发送到页面.

I found an script here: and he is working very well, but I've a problem, the script use an user access_token to upload the picture, dont's necessary ask permission of all users to upload the picture because the script use my administrator user to send to the page.

最大的问题是:用户访问令牌在2个小时后过期,或者当我的管理员用户未登录时,权限offline_access被终止,并且我不知道我的脚本将如何工作.

The big problem is: The user access token expire after 2 hours or when my admin user not logged in, the permission offline_access was discontinued and I don't know how my script will work.

我需要所有用户都可以使用该系统上传照片,任何人都知道我的工作方式吗?

I need that all user can upload photo using the system, anyone know how I can work?

这是PHP中的脚本:

`
require_once 'library/facebook.php';

$facebook = new Facebook(array(
    'appId'  => '<appid>',
    'secret' => '<appsecret>',
    'fileUpload' => true
));
$access_token = 'access_token';
$params = array('access_token' => $access_token);
$fanpage = 'page_id';
$album_id ='album_id';
$accounts = $facebook->api('/ADMIN_ACCOUNT/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');
$img = realpath("image_path");

$args = array(
    'message' => 'message to write in legend',
    '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>';
}`

推荐答案

如果您使用该脚本发布到粉丝页面的相册,那么您应该获得一个 page 访问令牌-他们没有不会过期.

If you’re using that script to post to a fan page’s album, then you should get a page access token – they don’t expire.

详细信息请参见此处: https://developers.facebook.com/docs/authentication/pages /

Details see here: https://developers.facebook.com/docs/authentication/pages/

这篇关于access_token-用于在粉丝页面相册中上传照片的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆