dongqiu9018 2013-09-04 02:36
浏览 44
已采纳

使用PHP SDK(如RSS Graffiti)自动发布到Facebook

I want to post auto on facebook with php SDK like RSS Graffiti does so i have this script on every thing is good and working but i am facing one problem here is my script

$facebook = new Facebook(array(
            'appId' => 'appId',
            'secret' => 'secret',
            'fileUpload' => true
        ));   


$facebook->setExtendedAccessToken();
$access_token = $_SESSION["fb_".$fb_appId."_access_token"];

$facebook->setAccessToken($access_token);
$accessToken = $facebook->getAccessToken();

$user_id = $facebook->getUser();
$fbuser = $user_id;

echo $accessToken ;

this script take accessToken and store it into mysql so i can use it for 60 days .. i am using this app for myself only so i am using mysql instead of RSS, so post go dialectally on FB as it get posted on my site ...

Problem:

Every time i want to get accessToken i have to login to facebook manually (can it be done automatically to get just token)?

can i use my login details in SDK to auto login and get accessToken ? if so how ?

i want to get accessToken every 60 day to make it working.

so please help

  • 写回答

1条回答 默认 最新

  • dongxu7408 2013-09-04 19:30
    关注

    It seems you have lot of confusions regarding the access token.

    Please remember following points about the user access token-

    1. Short-lived token can only be obtained with the user interacting your application( more specifically- when the user login/authorizes your app)

      Validity: upto 2 hours

    2. Long-lived token can only be exchanged with short-lived token. Using the following request:

      GET /oauth/access_token?  
        grant_type=fb_exchange_token&           
        client_id={app-id}&
        client_secret={app-secret}&
        fb_exchange_token={short-lived-token}
      

      Validity: 60 days

    So, it's quite obvious that if you want to refresh the login-lived token (before it expires), you're going to need a short-lived token which you can obtain by sending the person back to the login flow used by your application (not re-authorization really, but just to obtain the new token)

    You can read more about Expiration and Extending Tokens on the developers site here.

    EDIT

    If you just want to post to your fan page, you can use the page_access_token. A never-expiring fan page token could be obtained with a one-time process; and you can use that to do the actions on your page.

    See the accepted answer of this discussion: What are the Steps to getting a Long Lasting Token For Posting To a Facebook Fan Page from a Server

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!