从 cookie 获取访问令牌以与 Facebook Graph API 一起使用

发布于 2024-10-18 20:43:30 字数 631 浏览 2 评论 0原文

假设我有一个用户登录到 Facebook(Cookie 保存在浏览器的缓存中),获取其访问令牌的最简单方法是什么? 我正在尝试 Facebook 的 Graph API,我不想为了获取访问令牌而创建应用程序(至少现在不想)。

如果我没记错的话,几天前我去了 http://graph.facebook.com/me在我的浏览器上(登录时),它将我重定向到 http://graph.facebook.com/ me?access_token=...,但现在我明白了(并且没有重定向):

{  
      "error":      {  
      "type":    "OAuthException",  
      "message": "An active access token must be used to query information about the current user."  
   }  
}

不幸的是,我不能依赖以前回答的问题,因为我坚信事情最近发生了变化。

Assuming I have a user logged in to Facebook (Cookies are saved in the browser's cache), what is the simplest way to get its access token?
I'm experimenting with Facebook's Graph API, and I don't want to bother with creating an application in order to get access tokens (at least not now).

If I remember correctly, a few days ago I went to http://graph.facebook.com/me on my browser (while being logged in), which redirected me to http://graph.facebook.com/me?access_token=..., but now I get that instead (and no redirection):

{  
      "error":      {  
      "type":    "OAuthException",  
      "message": "An active access token must be used to query information about the current user."  
   }  
}

Unfortunately, I couldn't rely on previously answered questions, since I strongly believe things changed very recently.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

百合的盛世恋 2024-10-25 20:43:30

您需要的所有文档都在这里:
https://developers.facebook.com/docs/authentication/

如果您只想要一个为自己测试 API 中的某些内容的访问令牌,您可以使用 Graph API Explorer ( https://developers .facebook.com/tools/explorer )为您生成该应用程序的访问令牌并将其复制/粘贴到您的代码中。

请务必包含“offline_access”权限以获得不会很快过期的令牌。

All the docs you're going to need are here:
https://developers.facebook.com/docs/authentication/

If you just want a single access token for yourself to test some things in the API, you could use the Graph API Explorer ( https://developers.facebook.com/tools/explorer ) to generate an access token for you for that app and copy/paste it to your code.

Be sure to include the 'offline_access' permission to get a token which won't quickly expire.

妄司 2024-10-25 20:43:30

你根本做不到!
您需要创建一个应用程序才能生成 access_token(成功验证/授权后)。有关此内容的更多信息,请参见此处

Simply you can't!
You need to create an application to be able to generate an access_token (after a successful authentication/authorization). More about this here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文