简体   繁体   English

使用javascript SDK和应用访问令牌获取Facebook用户名

[英]Get Facebook user name with javascript SDK and app access token

I've coded some php which retrieves facebook user ids, stored in my database, and then goes on to request their user names. 我已经编写了一些php,它检索存储在我的数据库中的facebook用户ID,然后继续请求他们的用户名。 It all works fine, however this process adds an additonal 1.8 seconds to my pageload, which I would like to avoid if possible. 一切正常,但是此过程为我的页面加载增加了1.8秒的时间,如果可能的话,我希望避免这种情况。

So I rebuilt the code, and added some javascript which looks for the user ids and then requests the user names. 因此,我重新构建了代码,并添加了一些JavaScript,这些JavaScript会查找用户ID,然后请求用户名。 This method runs a lot faster and my page load is 1.8 sec shorter. 此方法运行速度快得多,我的页面加载时间缩短了1.8秒。 However in order to make it work I'm adding my app access token to the javascript, which ofcourse is a security black hole 但是,为了使其正常工作,我将我的应用程序访问令牌添加到了javascript中,这当然是一个安全黑洞

The javascript fb.api call looks like that at the moment javascript fb.api调用现在看起来像这样

        FB.api('/'+userid, {access_token : 'appAccessToken'}, function(response) {
            userNameSpan.text(response.name);
        });

Is there any other way I can make this work, without falling back to the pure server-side solution which is awfully slow? 我还有其他方法可以完成这项工作,而不必退回到纯慢的服务器端解决方案吗?

I'm getting no answers at all to my questions lately. 我最近对我的问题一无所获。 Anyway, the only other solutions I can think of are ajax calling the php file, which will be requesting the user names itself, or storing the user names in the database along with the user ids. 无论如何,我能想到的唯一其他解决方案是ajax调用php文件,该文件将请求用户名本身,或者将用户名与用户ID一起存储在数据库中。

The ajax solution is problematic for a lot of reasons, mainly because the platform is joomla and the php is a custom module, which means that I will have to either call the file outside of the joomla framework (security issues arise) or build my own helper file for the custom module in order for it to work with the com_ajax component of joomla, which ofcourse is a timesink. 由于许多原因,ajax解决方案存在问题,主要是因为平台是joomla,而php是自定义模块,这意味着我将不得不在joomla框架之外调用文件(出现安全问题)或构建自己的文件定制模块的帮助文件,以便它与joomla的com_ajax组件一起使用,这当然是一个时间浪费。

The database solution has the downside that the usernames will not be dynamic, meaning that if a user chnages his/her user name after he/she has been added in the database, the change will not be available to me. 数据库解决方案的缺点是用户名不会是动态的,这意味着如果用户在将他/她添加到数据库后更改了他/她的用户名,则该更改将对我不可用。 I guess I could also store the time the user was inserted in the database and check how much time has passed, and perform a facebook request for his/her username only after a predefined time has passed, and then updating the database if the username has changed. 我想我还可以存储将用户插入数据库的时间并检查已过去了多少时间,并且仅在经过预定义的时间后才对他/她的用户名执行Facebook请求,然后如果用户名已改变。 Not quite dynamic, but close enough 不太动态,但足够接近

If any1 has any other ideas, please don't be shy 如果有任何其他想法,请不要害羞

Although I'm gonna go for the database solution, I found another solution that can decrease the pageload significantly. 尽管我打算使用数据库解决方案,但我发现了另一个可以显着减少页面加载量的解决方案。

Instead of making an api call for each user, you can do a batch call, requesting info about many users in one call. 您可以进行批量调用,而不是为每个用户进行api调用,而是在一个调用中请求有关许多用户的信息。 It is explained here https://developers.facebook.com/docs/graph-api/making-multiple-requests 在这里进行解释https://developers.facebook.com/docs/graph-api/making-multiple-requests

That would cut down my calls from 6 to 1. However since reading up a bit about facebook names, I realized they do not change that often any more, so the database solution is better for my case 这样可以将我的通话次数从6减少到1。但是,由于阅读了一些有关Facebook名称的信息,我意识到它们不再经常更改,因此数据库解决方案对于我的情况更好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不使用SDK的情况下获取Facebook用户访问令牌? - How to get facebook user access token without using sdk? Facebook Javascript SDK新访问令牌在后台 - Facebook Javascript SDK new access token in the background 生成应用令牌Facebook Javascript SDK时出错 - Error generating App Token Facebook Javascript SDK facebook php sdk如何从javascript sdk获取访问令牌? - How can facebook php sdk get the access token from javascript sdk? 错误:“您必须提供应用访问令牌,或作为应用所有者或开发者的用户访问令牌”使用 Facebook 登录 SDK - Error: "You must provide an app access token, or a user access token that is an owner or developer of the app" using Facebook Login SDK 使用Facebook Javascript SDK访问用户位置数据 - Access user location data with Facebook Javascript SDK Facebook Javascript SDK - 无法访问用户电子邮件 - Facebook Javascript SDK - Cannot access user email 在Facebook Javascript SDK中使用“应用程序访问令牌”吗? - Use “app access tokens” with the Facebook Javascript SDK? 使用JavaScript SDK获取linkedin访问令牌 - Get linkedin Access Token with JavaScript SDK 如果我们具有使用Javascript的访问令牌,则登录Facebook用户名 - Logged in Facebook user's name if we have access token using Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM