I am trying to get the API on the react-native interface by calling with Axios but getting a network error. My API is written in .net core version 3.0.
I have successfully tried postman but failed to call
Please help me fix it.enter image description here
enter image description here
You can passing header in your axios request to fix CORS as Ketan Rampteke's reply.
Follow link .
Chào thân ái người anh em <3
Related
Hello I am a beginner in mobile app development. I am doing project in react native.In my app I need to fetch the food details from foodb website using API. I tried in postman to get response but I am getting error.
Error:
{
"error": "food_name is missing, api_key is missing"
}
Kindly guide me to resolve this problem. Thanks in Advance
You have to add parameter as query parameters:
curl -X GET 'https://foodb.ca/api/v1/foodreport/food?food_name=Angelicaa&api_key=d9b6cec3eb561db6f920a0797ba49f3e'
I'm trying to connect to the Twinfield API. I have registered an app in the developer portal, and created a callback URI. My call looks as follows:
https://login.twinfield.com/auth/authentication/connect/authorize?redirect_uri=https://oauth.pstmn.io/v1/callback&response_type=id_token+token&client_id=###&client_secret=#####
Link to twinfield api documentation
However I get the error stating that the client application is not known or is not authorized.
Can someone help me with this problem?
Think you are missing the code, see below the response_type
&response_type=code&scope=openid+twf.user+twf.organisation+twf.organisationUser+offline_access&redirect_uri=https://oauth.pstmn.io/v1/callback&
Once you've run this, you get a code and together with basic64encoding of your client_id:client_secret would profide you an access code.
The whole request should look like:
https://login.twinfield.com/auth/authentication/connect/authorize?client_id={xxxx}&response_type=code&scope=openid+twf.user+twf.organisation+twf.organisationUser+offline_access&redirect_uri=https://oauth.pstmn.io/v1/callback&state=SOME_RANDOM_STATE&nonce=SOME_RANDOM_NONCE
for me to get this working in postman I need to copy the whole link into the browser, login there and then get from the return link the code when you see the page "Your call is authenticated"
I am trying to create a React Native / Expo app where I can use the YouTube Data V3 API's (video insert) but I am having difficulty understanding how to use fetch() in React Native to get the access_key by authenticating a google user through Google oauth2 consent screen.
This is my code so far:
fetch(
'https://accounts.google.com/o/oauth2/v2/auth?' +
'client_id=' + clientId + '&' +
'redirect_uri=http://localhost:19006&' +
'response_type=token&' +
'scope=https://www.googleapis.com/auth/drive.metadata.readonly&' +
'include_granted_scopes=true&' +
'state=pass-through value',
{
method: 'GET'
}
);
I am getting from origin 'http://localhost:19006' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. and Uncaught (in promise) TypeError: Failed to fetch error in Chrome console. If I copy paste the link in a new tab in my browser the consent page is working.
I managed it to work using Javascript code but in React Native I can't get it to work. I am following the documentation at https://developers.google.com/identity/protocols/oauth2/javascript-implicit-flow#js-client-library
I searched GitHub and StackOverflow for possible solutions but I can't find any for React Native/Expo. I also tried the Node.Js Googleapis client library but as I understand it is not compatible with React Native/Expo.
You can try to use the following npm package or search for the relevant npm package like below for AppAuth react-native:
https://github.com/FormidableLabs/react-native-app-auth
Also check out the documentation or example:
https://developer.okta.com/blog/2018/03/16/build-react-native-authentication-oauth-2
I have 2 items set up in Auth0:
Application - Single Page Application
API - Custom API, machine to machine
I've followed the instruction in the link below to call the custom API:
https://auth0.com/docs/quickstart/spa/vuejs/02-calling-an-api
I've downloaded the sample with settings configured for both items mentioned above. The Vue app are able to log in correctly, and are able to call the external API by using the downloaded example codes (the external API, "backend", in the example code was written in Node JS).
However, when I change the backend to my Laravel/Lumen app which already set up for item no.2 (custom API), the Vue app received 401 unauthorized error. So, I copied the access token retrieved through Vue:
const accessToken = await this.$auth.getTokenSilently();
console.log(accessToken);
And try to call the Lumen backend with this access token - and it works perfectly fine!
Is there a setting somewhere that I might've missed to enable Vue & Lumen to work with Auth0?
p/s: The custom Lumen API was made following the instruction from:
https://auth0.com/blog/developing-restful-apis-with-lumen/
Ok it turns out I made a mistake in the axios part of the sample code. The sample is using get, while my API is using post. So I ended up sending the header in the wrong axios parameter. Hope this helps someone that encountered the same problem.
user defined x-header doesnt send to api problem
We have a rest api configured with cors. We can access it with ajax, swift etc.
But when we try to send request from android with react-native application x-header doesnt sent in request header. Our parameters added as miscellaneous header and not sent to server.
We try to request with axios and fetch and xmlHttpRequest
By the way when we try the same request with react it works.
My environment:
android,
react-native,
axios,
fetch
xmlHttpRequest