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

160
Views
Hacer solicitudes de publicación a las API de Pinterest usando Axios

Actualmente estoy atascado en hacer solicitudes de publicaciones a la API de pinterest. Si bien siento que mi código funciona bien, sigo recibiendo "Invalid Request Body" de la API de pinterest.

Según la documentación en su sitio, así es como dijeron que se debe hacer la solicitud:

 curl -X POST https://api.pinterest.com/v5/oauth/token --header "Authorization: Basic {base64 encoded string made of client_id:client_secret}" --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'grant_type=authorization_code' --data-urlencode 'code={YOUR_CODE}' --data-urlencode 'redirect_uri=http://localhost/'

Así es como hice la solicitud usando Axios desde mi aplicación ExpressJS:

 const redirectUrl = process.env.PINTEREST_OAUTH_CALLBACK_URL; const clientId = process.env.PINTEREST_APP_ID; const clientSecret = process.env.PINTEREST_APP_SECRET; let url = 'https://api.pinterest.com/v5/oauth/token'; let accessTokenRequestBody = { code: encodeURIComponent(code), //code is defined at the top as received from pinterest grant_type: encodeURIComponent("authorization_code"), redirect_uri: encodeURIComponent(redirectUrl) } console.log(`RequestBody =${JSON.stringify(accessTokenRequestBody, null, 2)}`); const clientIdAndSecretBase64 = Buffer.from(`${clientId}:${clientSecret}`).toString('base64'); axios.post(url, accessTokenRequestBody, { headers: { 'Content-Type': 'application/application/x-www-form-urlencoded; charset=UTF-8', 'Authorization': `Basic ${clientIdAndSecretBase64}` } }).then((response) => { let responseData = response.data; console.log(`Pinterest ResponseData = ${JSON.stringify(responseData, null, 2)}`); }).catch((e) => { console.log(`${JSON.stringify(e.response.data)}`); });

Aquí está la respuesta que sigo recibiendo:

 {code:1, message:"Invalid request body"}

Aquí está el enlace a la documentación con la que estoy trabajando.

https://developers.pinterest.com/docs/api/v5/#tag/Authentication

Por favor, ¿qué podría estar haciendo mal aquí, porque creí que proporcioné todo lo que necesitaban en la solicitud?

Gracias anticipadas por su entrada.

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

0

const redirectUrl = process.env.PINTEREST_OAUTH_CALLBACK_URL; const clientId = process.env.PINTEREST_APP_ID; const clientSecret = process.env.PINTEREST_APP_SECRET; let url = 'https://api.pinterest.com/v5/oauth/token'; let body = { 'code': code, //code is defined at the top as received from pinterest 'grant_type': 'authorization_code', 'redirect_uri': redirectUrl }; // Fix code let accessTokenRequestBody = Object.keys(body) .map(k => `${encodeURIComponent(k)}=${encodeURIComponent(body[k])}`) .join('&'); console.log(`RequestBody =${JSON.stringify(accessTokenRequestBody, null, 2)}`); const clientIdAndSecretBase64 = Buffer.from(`${clientId}:${clientSecret}`).toString('base64'); axios.post(url, accessTokenRequestBody, { headers: { 'Content-Type': 'application/application/x-www-form-urlencoded; charset=UTF-8', 'Authorization': `Basic ${clientIdAndSecretBase64}` } }).then((response) => { let responseData = response.data; console.log(`Pinterest ResponseData = ${JSON.stringify(responseData, null, 2)}`); }).catch((e) => { console.log(`${JSON.stringify(e.response.data)}`); });
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!