
[英]Get Facebook user name with javascript SDK and app access token
[英]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 上的广告报告。
这些是我在前端(React)中使用的函数:
export function initFacebookSdk() {
return new Promise(resolve => {
// wait for facebook sdk to initialize before starting the react app
window.fbAsyncInit = function () {
window.FB.init({
appId: 'app-id',
cookie: true,
xfbml: true,
version: 'v14.0'
});
resolve()
};
});
}
export const FbLogin = () => {
loadFacebookSDK(document, "script", "facebook-jssdk")
initFacebookSdk()
return new Promise( resolve => {
window.FB.login(response => {
if (response.authResponse) {
resolve(response);
} else {
resolve(response);
}
}, {scope: 'ads_management,ads_read'});
})
}
所以我调用这个函数
const response = await FbLogin();
我将令牌发送到后端,这就是它使用路由的方式:
try {
const { data: accountsInfo } = await axios({
url: `https://graph.facebook.com/v${FB_GRAPH_API_VERSION}/me/adaccounts?access_token=${accessToken}&pretty=1&limit=100`,
method: 'GET',
});
res.status(200).json({success: true, accountsInfo})
} catch (err) {
console.log(err);
res.status(500).json({success: false})
}
这是我在尝试使用用户令牌时遇到的错误:
'OAuth "Facebook Platform" "invalid_request" "(#100) You must provide an app access token, or a user access token that is an owner or developer of the app"'
有谁知道为什么这会发生在我身上? 帮助 :(
你没有展示你是如何将令牌发送到后端的,你真的收到了吗? 您的问题需要更多详细信息,以及您使用 Facebook sdk 的方式,只要您使用反应方式,您就不会使用状态和自定义挂钩的力量来减少错误的可能性,如下所示:
export const useFacebookSdk = () => { const [fcbSdk, setFcbSdk] = useState(); useEffect(() => { window.fbAsyncInit = function () { FB.init({ appId: 'app-id', autoLogAppEvents: true, cookie: true, xfbml: true, version: 'v14.0', status: true, }); setFcbSdk((prev) => ({ ...prev, login: () => ((scope) => FB.login((r, handleLoginRes) => handleLoginRes(r), { scope })), logout: () => (() => { FB.logout() }), FcbApiReq: ((path, method, params, cb) => FB.api(path, method, params, cb)), getLoginStatus: (() => { let status; FB.getLoginStatus(e => { return status = e }) return status }), })) } }, []) return { ...fcbSdk } } // use it like this // import { login, logout, FcbApiReq, getLoginStatus} from "./pathOfFile.js" // or if it s in the same file // { login, logout, FcbApiReq, getLoginStatus} =useFacebookSdk()
祝你好运
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.