react-native-dialogflow icon indicating copy to clipboard operation
react-native-dialogflow copied to clipboard

Authentication V2: "status": "UNAUTHENTICATED"

Open pramodkumar005 opened this issue 4 years ago • 7 comments

Unable to get access

 constructor(props) {
        super(props);

        Dialogflow_V2.setConfiguration(
            "[email protected]",
            '-----BEGIN PRIVATE KEY-----\nMIIEvgIBADAN...1oqO\n-----END PRIVATE KEY-----\n',
            Dialogflow_V2.LANG_ENGLISH_US,
            'testv2-3b5ca'
        );
    }

componentDidMount(){
  Dialogflow_V2.requestQuery("Some text for your Dialogflow agent", result=>console.log(result), error=>console.log(error));
}

error recieved: {"error": {"code": 401, "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "status": "UNAUTHENTICATED"}}

pramodkumar005 avatar May 24 '20 13:05 pramodkumar005

I've tried generating new service accounts and making sure the API is enabled on the project. Any idea what could be causing this?

lewismclennan avatar Jul 24 '20 11:07 lewismclennan

Sadly same issue here. Been stuck on this for over 2 weeks. Anyone got an alternative method?

eniga avatar Jul 29 '20 06:07 eniga

This is how I do it:

const configureDialogFlow = (clientId: number | null) => {
  Dialogflow_V2.setConfiguration(
    env.DIALOGFLOW_CLIENT_EMAIL,
    env.DIALOGFLOW_PRIVATE_KEY,
    Dialogflow_V2.LANG_ENGLISH_GB,
    env.DIALOGFLOW_PROJECT_ID,
  );
  const permanentContexts = [
    {
      name: 'Auth',
      parameters: {
        lifespanCount: 100,
        AccessToken: clientId,
      },
    },
  ];
  Dialogflow_V2.setPermanentContexts(permanentContexts);
};

martinlockett avatar Aug 25 '20 11:08 martinlockett

Does anyone know a solution to this? The previous post requires TypeScript

RamithaSRavi avatar Jul 15 '21 01:07 RamithaSRavi

Same here.

Jefferson-Lima-Santos avatar Jul 12 '22 16:07 Jefferson-Lima-Santos

Hello, has anyone figured this out? I'm facing the same problem and have been stuck on this for weeks

shakshakeeb avatar Dec 30 '22 01:12 shakshakeeb

I am using Expo and was having the same problem,

I checked my package.json, and it was using version "^3.1.0" I changed to "3.1.1" and npm i and restarted.

Now, it works!

this is my onSend function


    const onSend = async (message) => {
        setMessages((previousMessages) => GiftedChat.append(previousMessages, message));
        let msg = message[0].text;

        try {
            const result = await new Promise((resolve, reject) => {
                Dialogflow_V2.requestQuery(
                    msg,
                    (result) => {
                        resolve(result);
                    },
                    (error) => {
                        reject(error);
                    }
                );
            });

            console.log(result);
            handleGoogleResponse(result.queryResult.fulfillmentText);
        } catch (error) {
            console.error(error);
        }
    };

timkim0713 avatar Aug 17 '23 18:08 timkim0713