Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
Funciones de Firebase: el valor del argumento "datos" no es un documento válido de Firestore

Estoy tratando de seguir un tutorial de fireship con oAuth2 con el siguiente código.

Todas las funciones se inicializaron correctamente, pero apareció este mensaje de error cuando intenté autorizar la aplicación a través de Twitter. El mensaje de error está debajo.

⚠ funciones: Error: el valor del argumento "datos" no es un documento válido de Firestore. No se puede usar "indefinido" como valor de Firestore (se encuentra en el campo "accessToken"). Si desea ignorar valores indefinidos, habilite ignoreUndefinedProperties .

El código está abajo:

 const functions = require('firebase-functions') const admin = require('firebase-admin') admin.initializeApp() // Database reference const dbRef = admin.firestore().doc('tokens/demo') const TwitterApi = require('twitter-api-v2').default const twitterClient = new TwitterApi({ clientId: 'aabbcc', clientSecret: 'aabbcc', }) const callbackURL = 'http://127.0.0.1:5001/primussoft-74a49/us-central1/callback' // STEP 1 - Auth URL exports.auth = functions.https.onRequest(async (request, response) => { const { url, codeVerifier, state } = twitterClient.generateOAuth2AuthLink( callbackURL, { scope: ['tweet.read', 'tweet.write', 'users.read', 'offline.access'] } ) // store verifier await dbRef.set({ codeVerifier, state }) response.redirect(url) }) // STEP 2 - Verify callback code, store access_token exports.callback = functions.https.onRequest(async (request, response) => { const { state, code } = request.query const dbSnapshot = await dbRef.get() const { codeVerifier, state: storedState } = dbSnapshot.data() if (state !== storedState) { return response.status(400).send('Stored tokens do not match!') } const { client: loggedClient, accessToken, refreshToken, } = twitterClient.loginWithOAuth2({ code, codeVerifier, redirectUri: callbackURL, }) await dbRef.set({ accessToken, refreshToken }) const { data } = loggedClient.v2.me() // start using the client if you want response.send(data) }) // STEP 3 - Refresh tokens and post tweets exports.tweet = functions.https.onRequest(async (request, response) => { const { refreshToken } = dbRef.get().data() const { client: refreshedClient, accessToken, refreshToken: newRefreshToken, } = twitterClient.refreshOAuth2Token(refreshToken) await dbRef.set({ accessToken, refreshToken: newRefreshToken }) // const { data } = await refreshedClient.v2.tweet( // nextTweet.data.choices[0].text // ) const { dataone } = { id: 'testid', text: 'a tweet from me' } response.send(dataone) }) exports.tweet = functions.https.onRequest((request, response) => {})

De hecho, estaba tratando de seguir un tutorial de fireship en este enlace https://youtu.be/V7LEihbOv3Y

Cualquier ayuda sería muy apreciada.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El método refreshOAuth2Token devuelve una promesa. Intente agregar await como se muestra a continuación:

 const { client: refreshedClient, accessToken, refreshToken: newRefreshToken, } = await twitterClient.refreshOAuth2Token(refreshToken)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!