react-native-background-geolocation
react-native-background-geolocation copied to clipboard
Getting Unauthorized access (Error code 401)
Your Environment
Plugin version:4.12.1 Platform: Android OS version: Device manufacturer / model: OPPO/CPH2095 React Native version (react-native -v): 0.64
- Plugin config
const state:State = await BackgroundGeolocation.ready({
url:"http://92.204.135.120:8099/TomAPI/SaveLocationInformation",
locationTemplate: '{"Latitude":<%= latitude %>,"Longitude":<%= longitude %>,"TimeStamp": "<%= timestamp %>"}',
autoSync:true,
autoSyncThreshold:5,
batchSync:true,
maxBatchSize:50,
params: {
ClientId: 69,
},
headers: {
"authorization":'Bearer ' + getToken.data.Token ,
"X-FOO": "BAR"
},
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
//transistorAuthorizationToken: token,
// Geolocation
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_NAVIGATION,
distanceFilter: 10,
stopTimeout: 5,
// Permissions
locationAuthorizationRequest: 'Always',
backgroundPermissionRationale: {
title: "Allow {applicationName} to access this device's location even when closed or not in use.",
message: "This app collects location data to enable recording your trips to work and calculate distance-travelled.",
positiveAction: 'Change to "{backgroundPermissionOptionLabel}"',
negativeAction: 'Cancel'
},
// HTTP & Persistence
locationsOrderDirection:"DESC",
maxDaysToPersist: 14,
// Application
stopOnTerminate: false,
startOnBoot: true,
enableHeadless: true
});
401 comes from your server.
Why do you leave the sample header "X-FOO": "BAR" in your headers?
I have Tried removing it Also , but otherwise my syntax for writing token is correct?
Why don’t you debug this at your server and observe the incoming headers to determine why your server does not like the provided token?
That I will do after making sure I am sending the token in correct way from my app, I have just followed the documentation for writing url and token
See Mozilla MDN docs for information about Bearer token.
I Use the Bearer token while calling other API's so nothing wrong in that , But should I use the authorization keyword only ?
headers: {
"authorization":'Bearer ' + getToken.data.Token ,
},
The Config.headers are applied to the http request exactly as provided. There is nothing unusual about your authorization header.
consult with your server logs.
Hi I pass a source parameter also inside my header when I call any API ,May be I am getting error due to this , What will be the way to pass source inside header with double quotes or without double quotes ?
HTTP header values are always of type String
so I should use { "source": "92.204.135.120" }
?
“HTTP header values are always of type String” implies that values must always be enclosed in quotes.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.