Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Firebase Auth REST API:OAuth使用Twitter登录时出现错误32“;“无法验证您的身份”;_Node.js_Twitter_Firebase Authentication_Twitter Oauth_Node Request - Fatal编程技术网

Node.js Firebase Auth REST API:OAuth使用Twitter登录时出现错误32“;“无法验证您的身份”;

Node.js Firebase Auth REST API:OAuth使用Twitter登录时出现错误32“;“无法验证您的身份”;,node.js,twitter,firebase-authentication,twitter-oauth,node-request,Node.js,Twitter,Firebase Authentication,Twitter Oauth,Node Request,我正在Node.js中编写一个函数,通过RESTAPI(使用库发出请求),使用Twitter凭据将用户登录到Firebase。我可以使用Twitter凭据发布推文,但尝试使用/accounts:signInWithIdp登录Firebase时返回以下错误: { error: { code: 400, message: 'INVALID_IDP_RESPONSE : Failed to fetch resource from https://api.twitter.com/1.1

我正在Node.js中编写一个函数,通过RESTAPI(使用库发出请求),使用Twitter凭据将用户登录到Firebase。我可以使用Twitter凭据发布推文,但尝试使用
/accounts:signInWithIdp
登录Firebase时返回以下错误:

{ error: 
   { code: 400,
     message: 'INVALID_IDP_RESPONSE : Failed to fetch resource from https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true, http status: 401, http response: {"errors":[{"code":32,"message":"Could not authenticate you."}]}',
     errors: [ [Object] ] } }
这是我的代码:

loginWithOAuth = (idToken, postBody, onCompletion, onError) => {
    var form = {
        postBody: querystring.stringify(postBody),
        requestUri: 'request uri',
        returnIdpCredential: 'false',
        returnSecureToken: 'true',
    }
    request.post({
        url: 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key=' + firebase_api_key,
        body: form,
        json: true
    }, (error, r, body) => {
        // ...
    });
}
其中
postBody
的形式为

{
    access_token: 'token',
    oauth_token_secret: 'token secret',
    providerId: 'twitter.com'
}
我的Twitter应用程序具有访问用户电子邮件的权限。我也在Firebase和Twitter中列出了
requestUri
。重新生成我的应用程序和用户密钥没有什么区别


我缺少什么?

postBody
不是字符串化对象,它是URL编码的:

var form = {
    postBody: 'access_token=[TWITTER_ACCESS_TOKEN]&oauth_token_secret=[TWITTER_TOKEN_SECRET]&providerId=twitter.com',
    requestUri: 'request uri',
    returnIdpCredential: 'false',
    returnSecureToken: 'true',
}

是的,我也试过。如果不清楚,很抱歉,
qs
指的是
querystring
哪个url编码对象。