0

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

Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
Harinder
  • 1,257
  • 8
  • 27
  • 54

1 Answers1

1

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

Community
  • 1
  • 1
Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
  • thx for replying ... 1st i dont want user to login with ...its just to update my posts to facebook page. so i am using Long-lived token.i am obtaining this tocken once in 60 days by getting my self login and storing it in database. 2nd - what i want is ... i dont want to login manually ... is there a way that i can set corn job for it to just login on my behalf and generate token and store in my database? 3rd $access_token = $_SESSION[ this read SESSION of my o\login to get token. – Harinder Sep 05 '13 at 03:15
  • Obviously it is not possible what are looking for. But if its all about a fan page you can use the never expiring page token. Ive updatd the ans. Ps dont forget to mark /accept ans if helped – Sahil Mittal Sep 05 '13 at 04:43