在FB.init中设置用户(访问令牌) [英] set user (access token) within FB.init

查看:122
本文介绍了在FB.init中设置用户(访问令牌)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使他们没有使用Facebook登录,我也希望将故事发布到用户时间轴.实际上,我将用户访问令牌存储在数据库中,如果用户使用电子邮件登录,我将为她检索访问令牌.它在php中效果很好(例如,在setAccessToken(token_from_database之后)获取朋友列表,但是当我发布故事时,它总是发布到当前fb登录帐户的时间轴上.

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.

我认为问题是由fb.init引起的:

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
        });
    };

及更高版本:

FB.api('/me/...

以登录帐户作为我",而不是我通过setAcccessToken在php中设置的帐户. 我如何发布到该帐户的时间轴(用token_from_database指定)?有什么主意吗?

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?

推荐答案

尝试将您要使用的访问令牌作为您提供给FB.apiparams对象的一部分–与它的工作方式应该相同在访问API服务器端时.

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'
  }
);

这篇关于在FB.init中设置用户(访问令牌)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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