0

我已经将fb AccounKit与离子应用程序(NodeJS服务器)集成在一起。前端部分已经完成,我可以发送和接收OTP和成功状态。当从nodeJS服务器交换令牌时,Facebook帐户提供了错误

不过,虽然从授权码获取客户端的令牌,我不断收到“”错误验证在\“的access_token \”令牌'”的错误。我跟着他们的官方文档中提到的相同的过程。

这是我的代码:?

var me_endpoint_base_url = 'https://graph.accountkit.com/v1.0/me'; 
token_exchange_base_url='https://graph.accountkit.com/v1.0/access_token'; 

var params = { 
    grant_type: 'authorization_code', 
    code: request.body.code, 
    access_token: app_access_token 
}; 
} 

// exchange tokens 
console.log(Querystring.stringify(params)) 
var token_exchange_url = token_exchange_base_url + '?' + Querystring.stringify(params); 
Request.get({url: token_exchange_url, json: true}, function(err, resp, respBody) { 
    console.log(respBody); 
    var view = { 
    user_access_token: respBody.access_token, 
    expires_at: respBody.expires_at, 
    user_id: respBody.id, 
    }; 
    var me_endpoint_url = me_endpoint_base_url + '?access_token=' + respBody.access_token; 
    Request.get({url: me_endpoint_url, json:true }, function(err, resp, respBody) { 
    console.log(respBody); 
    if (respBody.phone) { 
     view.method = "SMS" 
     view.identity = respBody.phone; 
    } else if (respBody.email) { 
     view.method = "Email" 
     view.identity = respBody.email.address; 
    } 
    }); 
}); 

请帮

回答

1

制作服务器到服务器的电话时,为令牌交换代码,您需要提供您的帐户套件应用程序秘密的访问令牌你发送。 所以访问tok en应该看起来像:

'AA|{app_id}|{app_secret}' 

例如,

var app_access_token = ['AA', app_id, app_secret].join('|'); 

您可以从Account Kit仪表板找到您的应用程序秘密。在developers.facebook.com上的应用产品部分下的“Account Kit”页面中,点击“Account Kit App Secret”框旁边的“Show”按钮查看您的应用秘密。

还记得你应该从来没有包括你的应用程序的秘密在客户端上运行的任何JavaScript代码。这个秘密只能用在你的服务器端node.js代码中,其他人不应该看到它。

+0

谢谢。我使用的是AppSecret而不是Accountkit的AppSecret。现在它的工作。 –

+0

@AravindhNagarajan:请将此答案标记为已接受的答案 – deksden

相关问题