在Facebook应用程序中使用PHP SDK请求扩展访问令牌的位置 [英] Where to request extended access token in Facebook App using PHP SDK

查看:148
本文介绍了在Facebook应用程序中使用PHP SDK请求扩展访问令牌的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们离线时,我需要访问我的用户的信息,我明白我需要使用一个持续60天的扩展访问令牌。我一直在看这个SO帖子如何扩展访问因为offline_access不推荐使用令牌的有效性,而且这表示我需要在我的base_facebook.php文件中加入所述方法,并调用该方法。



看看我的代码,没有任何明确的请求或使用访问令牌,所以我不确定如何请求扩展访问令牌。这篇文章我需要在Facebook API中使用访问令牌?解释说,使用PHP SDK,访问令牌会自动附加到api请求中,这将解释为什么我迄今为止从未遇到访问令牌。



所以我的问题是如何让用户使用PHP SDK方法登录扩展访问令牌getExtendedAccessToken()?



编辑:A这里的关键点在于,您似乎无法获得自己的应用程序的扩展访问令牌!我尝试过与我的一个测试用户,它工作正常!另一点需要注意的是,访问令牌工具将默认仅显示实际开发应用程序的人的访问令牌。要查看其他用户的访问令牌的具体信息,您需要转到调试器部分并在其中输入访问令牌。希望这有帮助。

解决方案

如果您没有看到任何访问令牌的引用,存储在会话变量中。您可以尝试在代码中添加 echo< pre>; print_r($ _ SESSION); exit(0); 以查看会话中存储的内容。如果您正在从PHP SDK调用getExtendedAccessToken(),则返回的访问令牌将自动被长时间保存。 。要在将其引导回您的站点后检索,可以使用getAccessToken()方法。然后,您将存储返回的值,并在以后使用setAccessToken($ stored_token)进行调用时使用它。



希望有帮助。


I need to get access to my user's information when they are offline and I understand that I need to use an extended access token which lasts 60 days. I have been looking at this SO post How to extend access token validity since offline_access deprecation and this says that I need to include the stated method in my base_facebook.php file and make a call to the method.

However, looking through my code there is no explicit request or use of access tokens anywhere so I'm unsure how to request an extended access token. This post Do I need to use access token in Facebook API? explains that using the PHP SDK the access token is automatically appended to the api requests, which would explain why I have never encountered access tokens so far.

So my question is how do I get the user to give an extended access token when they sign in using the PHP SDK method getExtendedAccessToken()?

EDIT: A key point here is that you can't seem to get an extended access token for your own app! I tried this with one of my test users and it worked fine! Another point to note is that the access token tool will only show by default the access tokens for the person who actually developed the app. To see the specifics of the access token for other users you need to go to the debugger part and input the access token there. Hope this helps.

解决方案

If you haven't seen any references to access tokens, they are most likely being stored in session variables. You could try adding echo "<pre>";print_r($_SESSION);exit(0); to your code to see what is stored in the session. You would add it somewhere after you have already been logged in.

If you are calling getExtendedAccessToken() from the PHP SDK, then the access token returned will automatically be long lived. To retrieve it after they are directed back to your site, you can use the getAccessToken() method. You would then store the returned value, and use it when you want to make calls later with setAccessToken($stored_token) .

Hope that helps.

这篇关于在Facebook应用程序中使用PHP SDK请求扩展访问令牌的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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