如何获得"Sign in with Twitter"使用 NodeJS



我试图在Twitter工作的情况下实现Sing In,但是我不断收到以下错误

哇! 此页面的请求令牌无效。它可能已被使用,或已过期,因为它太旧。请返回将您发送到此处的网站或应用程序,然后重试;这可能只是一个错误。

这是我的代码,我做错了什么?

// Server
var OAuth = require('oauth').OAuth;
var callbackUrl = null;
var oa = new OAuth(
    'https://api.twitter.com/oauth/request_token',
    'https://api.twitter.com/oauth/access_token',
    CONSUMER_KEY,
    CONSUMER_SECRET,
    '1.0',
    callbackUrl,
    'HMAC-SHA1'
);
const promise = new Promise((resolve, reject) => {
    oa.getOAuthRequestToken(function(error, token, secret, results) {
        resolve({
            token,
            secret,
        });
    });
});
var oauth = await promise;
return { oauth };
// Client
window.open(`https://api.twitter.com/oauth/authenticate?oauth_token=${twitter.oauth.token})`);

我还将回调 url 设置为与我在应用程序详细信息页面中相同的 url,但没有骰子!

var callbackUrl = 'http://0.0.0.0:3001/settings/social/twitter/oauth';

小说明,不确定是否有帮助,但我注意到返回的令牌比我在网上看到的示例短。例:

Mine: EBhy3AAAAAAA94TPAAABajDwCww%
Twitter Site: NPcudxy0yU5T3tBzho7iCotZ3cnetKwcTIRlX0iwRl0&

我的客户端代码有一个额外的"(">

window.open(`https://api.twitter.com/oauth/authenticate?oauth_token=${twitter.oauth.token})`);

应改为

window.open(`https://api.twitter.com/oauth/authenticate?oauth_token=${twitter.oauth.token}`);

最新更新