tbceng / tbcbottest-1

This is a group project from TBC dedicated towards creating a discord bot that has the ability to fact check statements sent by users.
2 stars 0 forks source link

Google api error #19

Closed oxzoid closed 1 year ago

oxzoid commented 1 year ago
bot.on('messageCreate',async` message => {
    if (message.content.startsWith('!check')){
        const [command, question] = message.content.split('|');
        console.log(command,question);
        if (!question) return message.channel.send(` Please include a fact to check.`);
        const url = `https://factchecktools.googleapis.com/v1alpha1/claims:search?key=${process.env.GOOGLE_API_KEY}&query=${encodeURIComponent(question)}`
        // await axios.post('https://factchecktools.googleapis.com/v1alpha1/claims:search', {
        // // headers:{key: process.env.GOOGLE_API_KEY},
        // params: {
        //     key: process.env.GOOGLE_API_KEY,
        //     query: question,
        //     languageCode: "en-US",
        // }
        await axios.get(url).then(res=>{
        if (res.data.claims) {
            let claim = res.data.claims[0]
            let review = res.data.claims[0].claimReview[0]
            if (review.textualRating === "True") {
                message.channel.send("fact is true.");  
            }
            else{
                message.channel.send("fact is false");
            }
            }
    })
    .catch(error => {
        console.error(error);
      });   
    }
oxzoid commented 1 year ago

my google api key shows invalid even though it is correct in the axios section documentation: https://developers.google.com/fact-check/tools/api https://developers.google.com/search/docs/appearance/structured-data/factcheck

code I was using as reference: https://github.com/tandpfun/discord-factcheck-bot/blob/main/commands/check.js

oxzoid commented 1 year ago

solved,dont use the service account api key, use the api key of ur main account/api console in the credentials not the key associated with the service account image