简体   繁体   English

你能帮我解决这个关于 json 的错误吗?

[英]Can you help me to solve this error about json?

I'm trying to connect Firebase using node.js我正在尝试使用 node.js 连接 Firebase

I have following code in my json file.我的 json 文件中有以下代码。

    const functions = require('firebase-functions');
    const hmac_sha256= require ('crypto-js/hmac_sha256');
    const request= require('request');
    const admin= require('firebase-admin');
    
    const service_Account= require('./service_account_key.json');
    const firebaseConfig= json.parse(process.env.FIREBASE_CONFIG);
    firebaseConfig.credential= admin.credential.cert("service_Account");
    admin.initializeApp(firebaseConfig);
    
    exports.getCustomToken = functions.https.onRequest((req,res)=>{
        const  accessToken= req.query.access_Token;
        const FacebookAppSec= '72100b8d4ee21a85fc67d014f3b0c9fa';
        const AppSecretProof= hmac_sha256(accessToken,FacebookAppSec);
        //Validate token...
        const uri='https://graph.accountkit.com/v1.1/me?access_Token=${accessToken}&App_Proof=${AppSecretProof}';
    
    request({
            url= uri,
            json:true
    },(error,fbresponse,data)=>{
        if(error)
        {
            console.error('Access Token validation request failed\n',error);
            res.status(400).send(error);
        }
        else if(data.error)
        {
            console.error('Invalid Access Token\n',
                'access_Token=${accessToken}',
                'App_Proof=${AppSecretProof}',data.error);
            res.status(400).send(data);
        }
        else
        {
            admin.auth().createCustomToken(data.id)
            .then(CustomToken => res.status(200).send(CustomToken))
            .catch(error => {
                console.error('Create Custom Token Failed.',error);
                res.status(400).send(error);
            })
        }
            
    
    })
    
    })

After using command-firebase deploy I got this使用 command-firebase deploy 后,我得到了这个

    > G:\New folder\firebase_functions>firebase deploy
    
    === Deploying to 'eatitv2-8aa15'...
    
    i  deploying functions
    Running command: npm --prefix "$RESOURCE_DIR" run lint
    
    > functions@ lint G:\New folder\firebase_functions\functions
    > eslint .
    
    
    G:\New folder\firebase_functions\functions\index.js
      19:9  error  Parsing error: Shorthand property assignments are valid only in destructuring patterns
    
    ✖ 1 problem (1 error, 0 warnings)
    
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! functions@ lint: `eslint .`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the functions@ lint script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     C:\Users\Maaz Farooq\AppData\Roaming\npm-cache\_logs\2020-07-18T16_58_24_083Z-debug.log
    events.js:292
          throw er; // Unhandled 'error' event
          ^
    
    Error: spawn npm --prefix "%RESOURCE_DIR%" run lint ENOENT
        at notFoundError (C:\Users\Maaz Farooq\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:6:26)
        at verifyENOENT (C:\Users\Maaz Farooq\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:40:16)
        at ChildProcess.cp.emit (C:\Users\Maaz Farooq\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:27:25)
        at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
    Emitted 'error' event on ChildProcess instance at:
        at ChildProcess.cp.emit (C:\Users\Maaz Farooq\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:30:37)
        at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12) {
      code: 'ENOENT',
      errno: 'ENOENT',
      syscall: 'spawn npm --prefix "%RESOURCE_DIR%" run lint',
      path: 'npm --prefix "%RESOURCE_DIR%" run lint',
      spawnargs: []
    }
    
    Error: functions predeploy error: Command terminated with non-zero exit code1

I see many answers on stack overflow as well as on github, but nothing proceed.我在堆栈溢出以及 github 上看到了很多答案,但没有任何进展。 i have tried my best to solve it by myown also get help from online community but now posting this to all of you.我已尽我所能通过自己的方式解决它,也从在线社区获得帮助,但现在将其发布给大家。

The output shows that ESLint is giving you this error message on line 19 of index.js: output 显示 ESLint 在 index.js 的第 19 行给你这个错误信息:

19:9 error Parsing error: Shorthand property assignments are valid only in destructuring patterns 19:9 错误解析错误:速记属性分配仅在解构模式中有效

Line 19 is url= uri below:第 19 行是下面的url= uri

request({
        url= uri,
        json:true
},(error,fbresponse,data)=>{

If you want to give values to properties in a JavaScript objects, you have to use : instead of = , just like you did with json:true .如果要为 JavaScript 对象中的属性赋值,则必须使用:而不是= ,就像使用json:true一样。

request({
        url: uri,
        json:true
},(error,fbresponse,data)=>{

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM