Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set user (access token) within FB.init

i want to publish story to user timeline even when they were not login with facebook. Actually I stored user access token in the database, if the user login in with email, i'll retrieve the access token for her. It works well in php (e.g get friends list after setAccessToken(token_from_database), but when i post the story, it always post to current fb login account's timeline.

I think the problem is caused by fb.init:

window.fbAsyncInit = function() {
        FB.init({
            appId      : 'XXX', // App ID
            status     : true, // check login status
            cookie     : true // enable cookies to allow the server to access the session
            xfbml      : true  // parse XFBML
        });
    };

and later:

FB.api('/me/...

take login account as "me", not the one I set in php through setAcccessToken. How could i post to that account (specify with token_from_database) 's timeline? any idea?

like image 736
Mario Avatar asked Jul 19 '12 11:07

Mario


1 Answers

Try passing the access token you want to use as part of the params object you give to FB.api – it should work the same way as it does when accessing the API server-side.

FB.api(
  '/me/feed',
  'post',
  {
    access_token : 'access_token_for_some_user_fetched_from_your_database',
    additional_parameter_foo : 'bar'
  }
);
like image 109
CBroe Avatar answered Oct 24 '22 20:10

CBroe