【发布时间】:2025-12-03 21:50:02
【问题描述】:
我想创建一个简单的谷歌浏览器扩展来显示来自 Facebook 的新闻。
可以通过调用以下方式检索新闻提要:
https://graph.facebook.com/me/home?access_token=...
但我需要 access_token。
有人可以提示如何定义一个 JavaScript 函数,该函数在给定 YOUR_APP_ID 时将返回 access_token。这个功能也应该在 Chrome 扩展中工作。
互联网上的其他示例不起作用,因为:
- 我没有服务器。
- FB.getLoginStatus 似乎不起作用。
EDIT1:
我试过了:
function getAccessToken2(YOUR_APP_ID) {
alert("before FB.init");
FB.init({
appId : YOUR_APP_ID ,
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
alert("before FB.login");
FB.login( function (response) {
alert("response");
if ( response.authResponse ) {
alert("response.authResponse");
var access_token = response.authResponse.access_token;
alert(access_token);
}
} );
}
我有:
- alert("在 FB.init 之前");
- alert("FB.login 之前");
-
弹出窗口打开。它的网址是this。内容是:
API Error Code: 191 API Error Description: The specified URL is not owned by the application Error Message: Invalid redirect_uri: Given URL is not allowed by the Application configuration.
但我做了不得到:
- 警报(“响应”);
- 警报(access_token);
- 在调试模式下未发现其他 JavaScript 错误。
编辑2 这里的问题是我需要像桌面应用程序一样在 Facebook 进行身份验证。恕我直言。
【问题讨论】:
标签: javascript facebook google-chrome-extension oauth-2.0 access-token