React-native android , REST api post error getting "access denied" - react-native

Developing sample application, when i was call the post method
service in componentDidMount() getting error response access
denied. Only android it's having this issue. But I got this
response IOS Devices .
I researched this case Most of the this issue get an based up on
NetWork same wife connection like emulator and my System this is
fine.
when i was check on AndroidManifest.xml file also getting
Internet Permissions also Accessed.But Still getting this Error in
Android. Please Solve this ,
Only getting in Android Device and emulator having this issue
other Platform device like IOS working fine.
Thanks in Advance.

If the REST server is on localhost in Android you'll have to use your IP instead of http://localhost.
If the rest server is not on localhost you might have to adjust the body and the headers. So instead of string body use a json object etc.
Your code:
fetch('site:ab4aca652284d7dc87ca1f347f2ac432#ori-eu-west-1.s‌​‌​earchly.co…
',{ method:'POST', headers:{ 'Accept':'application/json',
'Content-Type':'application/json' }, body:JSON.stringify(string)
}).then((response)=>response.json()).then((responseData)=>{
}).catch((err)=>{ console.error(err) })
rowDatanewOrders:{"status":"error","message":"access denied"}
make sure you have a valid json in body if you have the header 'Content-Type':'application/json', not a string as you have now!
more details about possible adjustments of the body and headers here:
https://github.com/facebook/react-native/issues/5222

Related

Trying to get Vimeo API to recognize the upload file

I am using Expo managed Workflow with react-native and trying desperately to not have to eject. The only sticking point in the entire app is allowing users of the app to upload video into a usable format. I am hoping to use Vimeo as the video hosting service.
I am authenticated and verified and interacting with the Vimeo API.
On my express server when I run this code:
let Vimeo = require('vimeo').Vimeo;
let client = new Vimeo({vimeo creds});
client.request({
method: 'GET',
path: '/tutorial'
}, function (error, body, status_code, headers) {
if (error) {
console.log(error);
}
console.log(body);
})
I see this message:
message: 'Success! You just interacted with the Vimeo API. Your dev environment is configured correctly, and the client ID, client secret, and access token that you provided are all working fine.',
next_steps_link: 'https://developer.vimeo.com/api/guides/videos/upload',
token_is_authenticated: true
I successfully uploaded a video from my express server using this code and placing the file on the same directory as the server code.
client.upload(
"{filename}",
{
'name': ' Test Video 1',
'description': 'The description goes here.'
},
function (uri) {
console.log('Your video URI is: ' + uri);
},
function (bytes_uploaded, bytes_total) {
var percentage = (bytes_uploaded / bytes_total * 100).toFixed(2)
console.log(bytes_uploaded, bytes_total, percentage + '%')
},
function (error) {
console.log('Failed because: ' + error)
}
)
Then, I added the same functionality to my web app locally for testing but not on an express server, trying to do it within a react native app running in a browser (for starters). I still get the message that says I am successfully interacting with Vimeo API and that I am authenticated.
However, When I try to add the file in the react native app with the exact same code, except this is how I am accessing the video file from react native: filename = require({pathToFile});
and the failed response says:
"Failed because: Unable to locate file to upload."
I do not know if the message is incorrect and if Vimeo API is having issues understanding the file or if it could be that because I am no longer running on a server.
So I keep trying to make sense of how to do this but wonder if I am missing something at this stage of testing.
Because...
I am able to upload the video to Firebase Storage by using expo-image-picker.
When I try to give the Vimeo API the file from what I have retrieved from the filesystem, it still says it is unable to locate file to upload.
In this case the string I am trying to upload looks like this: data:video/quicktime;base64,AAAAHGZ0eXBtcDQyAAAAAW…5AQLMKwEjd8ABNvCVAUgYoQFR1yYBVZYxAVX9NwFXEy8BYh0m
Any suggestions of a way to get Vimeo api to recognize this file?
I really want to use Vimeo for this project I can't find anything on stack overflow related to this except this one question which noone has attempted to answer:
Failed because: Unable to locate file to upload but path is correct (Vimeo API)

JsonRpc request from ios 12 sends empty content

I am using vue-json-rpc-client-fetch-withcredentials for comunication with my api via jsonRpc in my ionic5/vue project. Comunication works fine in browser and ios 13 (devices and simulators), but when i running app on ios 12, request’s response is "Invalid request". The reason of invalid request is, that reguest’s content is empty. Does anyone know why? I am using Capacitor to create ios version. I tried to create request with another ways, but i have still the same error.
I changed setting for headers on API server and it's working now. So, it's really the difference between
header('Access-Control-Allow-Headers: *');
and
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");

Why can't add headers to axios.get?

I'm using axios and vue.js to play with the Fortnite Tracker API.
In their documentation it's clearly said that we need to include the "TRN-Api-Key" in header.
I tested with Postman and It works.
And this is my axios function to make the request:
let url = `https://api.fortnitetracker.com/v1/profile/${this.platform}/${this.username}`;
// username and platform are from my Vue Component.
axios.get(url, {
headers: {
"TRN-Api-Key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxx" // of course from my account on their website.
}
})
.then(response => console.log(response.data))
I expect the output in json like in Postman but I had a 404 Error: "Network Error".
And in the Browser Network Debug I can't see the request header 'TRN-Api-Key'.
[EDIT]
If your app is running on a server you can write a short PHP-Script and use curl in it to access the API (I think it's even possible to generate PHPcode from Postman).
Just address this script with axios and submit your platform and usernameproperties to build the right url.
Or have a look at this post alternatively. Maybe the use of an other API like #kecinotrab provided in the acceptet answer will help you too.

API call works locally, but fails when deployed to heroku or zeit

The HTTP GET call works fine locally, but fails when the app is deployed to heroku or zeit.
Here is the code:
const searchUrl = "https:/hn.algolia.com/api/v1/search?query=" + searchTerm;
axios({
method: "get",
url: searchUrl,
responseType: "json"
})
I'm making a call to Hackernews API. But when I open network tab while loading the app in heroku, I see it is making the call to https://evening-chamber-42563.herokuapp.com/hn.algolia.com/api/v1/search?query= (the actual url should be https://hn.algolia.com/api/v1/search?query=), somehow it is inserting evening-chamber-42563.herokuapp.com/ in between the actual URL that I've specified.
I thought it might be a problem with heroku, and deployed my app on zeit to see if it fixes the issue. Same thing again. This time it made a request to https://hackernews-clone-bgbmdyblch.now.sh/hn.algolia.com/api/v1/search?query= (hackernews-clone-bgbmdyblch.now.sh is where my app is deployed).
I tried with native fetch, and axios library. Still same issue.
Hours of google searching didn't help me, so I'm posting this here. Any help appreciated. Thanks.
Turns out there was a typo in the URL (missing a '/' after the protocol). It worked fine after correcting it.
When I called fetch in my localhost with the incorrect URL (missing '/'), the browser corrected it for me. But it created problems when the app was deployed on a cloud platform.

PushWoosh Error : status code : 210 status_message: Invalid device token for Android

I am trying to register device token on pushwoosh services using API but it's returning me following response (Form Pushwoosh service) :
{ status_code: 210,
status_message: 'Invalid token: apa91bhosngjexchs528yuy-y4woqtkoo5b3ydddkh29etjm6eg9thg5urchcqaae32lavevq5vdco6mbyozyld4mqajg_t8-aaqnxiz6fr1gwnml7maurolpibo7-hj3at5l3i7zvzw',
response: null }
I am using Same API for iOS and it's working fine for iOS.
But the problem is with Android device. Also device token is correct (Started from "AP91...") and App is registered onGCM as well.
Thanks for help.
I got the solution and it's silly mistake I have done.
Just Uploading Answer if someone new learner get stuck, so it will helpful.
While making API call to pushwoosh registration we are sending following request in API.
"request":{
"application":"84170-XXXXX",
"push_token":deviceInfo.deviceToken,
"language":"en",
"hwid": deviceInfo.HardwareID,
"timezone": 3600,
"device_type":deviceType
}
Mistake was I missed hwid which is unique (We are using device Mac address now).
Also for Android "device_type" =3 and for ios "device_type"=1 But I earlier I was sending 1 for both (And thats the issue).
Now I am sending it according to device type. (As per given in pushwoosh docs).
and it's working fine now.
Thanks.