React native fetch post request not workingHow to use FormData in react-native?How do JavaScript closures work?How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request?JavaScript post request like a form submitHow to manage a redirect request after a jQuery Ajax callHow do I send a cross-domain POST request via JavaScript?Abort Ajax requests using jQueryHow does JavaScript .prototype work?How does data binding work in AngularJS?What is the difference between using constructor vs getInitialState in React / React Native?What is the difference between React Native and React?
Yosemite Fire Rings - What to Expect?
Is this toilet slogan correct usage of the English language?
Is aluminum electrical wire used on aircraft?
How do you make your own symbol when Detexify fails?
What should you do when eye contact makes your subordinate uncomfortable?
Do the primes contain an infinite almost arithmetic progression?
What is the evidence for the "tyranny of the majority problem" in a direct democracy context?
A social experiment. What is the worst that can happen?
How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?
Multiplicative persistence
The IT department bottlenecks progress. How should I handle this?
Lowest total scrabble score
How does the math work for Perception checks?
Mixing PEX brands
Open a doc from terminal, but not by its name
Why does the Sun have different day lengths, but not the gas giants?
What exact color does ozone gas have?
Extract more than nine arguments that occur periodically in a sentence to use in macros in order to typset
Has any country ever had 2 former presidents in jail simultaneously?
Is there an injective, monotonically increasing, strictly concave function from the reals, to the reals?
What does chmod -u do?
Moving brute-force search to FPGA
What is the highest possible scrabble score for placing a single tile
Temporarily disable WLAN internet access for children, but allow it for adults
React native fetch post request not working
How to use FormData in react-native?How do JavaScript closures work?How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request?JavaScript post request like a form submitHow to manage a redirect request after a jQuery Ajax callHow do I send a cross-domain POST request via JavaScript?Abort Ajax requests using jQueryHow does JavaScript .prototype work?How does data binding work in AngularJS?What is the difference between using constructor vs getInitialState in React / React Native?What is the difference between React Native and React?
According to Instagram API to this is a sample request to get access_token
.
curl -F 'client_id=XXXXXX'
-F 'client_secret=XXXXXX'
-F 'grant_type=authorization_code'
-F 'redirect_uri=XXXXXX'
-F 'code=XXXXXX'
https://api.instagram.com/oauth/access_token
If I run this in the terminal I can get a result that looks something like this:
"access_token": "fb2e77d.47a0479900504cb3ab4a1f626d174d2d",
"user":
"id": "1574083",
"username": "snoopdogg",
"full_name": "Snoop Dogg",
"profile_picture": "..."
The problem is that it doesn't work with react-native.
I am using this code to make a post request on react-native:
fetch('https://api.instagram.com/oauth/access_token',
method: 'POST',
headers:
'Accept': 'application/json',
'Content-Type': 'application/json'
,
body: JSON.stringify(
client_id: 'XXXXXX',
client_secret: 'XXXXXX',
grant_type: 'authorization_code',
redirect_uri: 'XXXXXX',
code: 'XXXXXX'
),
)
.then(res => res.json())
.then(obj =>
console.error(obj);
)
.catch((error) =>
console.error(error);
)
And I keep getting a response of You must provide a client_id.
I tried to create a jQuery code of this request which DOES WORK.
$.ajax(
type: "POST",
url: "https://api.instagram.com/oauth/access_token",
data:
client_id: 'XXXXXX',
client_secret: 'XXXXXX',
grant_type: 'authorization_code',
redirect_uri: 'XXXXXX',
code: 'XXXXXX'
,
success: function(html)
console.error(html)
,
error: function(html)
console.error(html)
);
A one liner ruby code which also DOES WORK
Net::HTTP.post_form(URI.parse('https://api.instagram.com/oauth/access_token'), 'client_id': 'XXXXXX','client_secret': 'XXXXXX','grant_type': 'authorization_code','redirect_uri': 'XXXXXX','code': 'XXXXXX').body
Can you seem to spot what is wrong with my code? It does work with jQuery.
javascript ajax react-native
|
show 4 more comments
According to Instagram API to this is a sample request to get access_token
.
curl -F 'client_id=XXXXXX'
-F 'client_secret=XXXXXX'
-F 'grant_type=authorization_code'
-F 'redirect_uri=XXXXXX'
-F 'code=XXXXXX'
https://api.instagram.com/oauth/access_token
If I run this in the terminal I can get a result that looks something like this:
"access_token": "fb2e77d.47a0479900504cb3ab4a1f626d174d2d",
"user":
"id": "1574083",
"username": "snoopdogg",
"full_name": "Snoop Dogg",
"profile_picture": "..."
The problem is that it doesn't work with react-native.
I am using this code to make a post request on react-native:
fetch('https://api.instagram.com/oauth/access_token',
method: 'POST',
headers:
'Accept': 'application/json',
'Content-Type': 'application/json'
,
body: JSON.stringify(
client_id: 'XXXXXX',
client_secret: 'XXXXXX',
grant_type: 'authorization_code',
redirect_uri: 'XXXXXX',
code: 'XXXXXX'
),
)
.then(res => res.json())
.then(obj =>
console.error(obj);
)
.catch((error) =>
console.error(error);
)
And I keep getting a response of You must provide a client_id.
I tried to create a jQuery code of this request which DOES WORK.
$.ajax(
type: "POST",
url: "https://api.instagram.com/oauth/access_token",
data:
client_id: 'XXXXXX',
client_secret: 'XXXXXX',
grant_type: 'authorization_code',
redirect_uri: 'XXXXXX',
code: 'XXXXXX'
,
success: function(html)
console.error(html)
,
error: function(html)
console.error(html)
);
A one liner ruby code which also DOES WORK
Net::HTTP.post_form(URI.parse('https://api.instagram.com/oauth/access_token'), 'client_id': 'XXXXXX','client_secret': 'XXXXXX','grant_type': 'authorization_code','redirect_uri': 'XXXXXX','code': 'XXXXXX').body
Can you seem to spot what is wrong with my code? It does work with jQuery.
javascript ajax react-native
Try your request withFormData
? Cause that what-F
oncurl
means. This SO answer explains how
– wicky
Mar 8 at 2:34
Where did you callfetch
method? Follow this example facebook.github.io/react-native/docs/network .Remember toreturn
it insidecomponentDidMount
– Vu Luu
Mar 8 at 2:34
@VuLuu I am calling it insidecomponentDidMount()
.
– David Angulo
Mar 8 at 2:37
Please replace yourfetch
content by:fetch('https://jsonplaceholder.typicode.com/todos/1') .then(response => response.json()) .then(json => console.log(json))
Is it work?
– Vu Luu
Mar 8 at 2:38
@VuLuu Yes get request does work. Also my request to Instagram goes through the only problem is that the parameters does not get passed.
– David Angulo
Mar 8 at 2:41
|
show 4 more comments
According to Instagram API to this is a sample request to get access_token
.
curl -F 'client_id=XXXXXX'
-F 'client_secret=XXXXXX'
-F 'grant_type=authorization_code'
-F 'redirect_uri=XXXXXX'
-F 'code=XXXXXX'
https://api.instagram.com/oauth/access_token
If I run this in the terminal I can get a result that looks something like this:
"access_token": "fb2e77d.47a0479900504cb3ab4a1f626d174d2d",
"user":
"id": "1574083",
"username": "snoopdogg",
"full_name": "Snoop Dogg",
"profile_picture": "..."
The problem is that it doesn't work with react-native.
I am using this code to make a post request on react-native:
fetch('https://api.instagram.com/oauth/access_token',
method: 'POST',
headers:
'Accept': 'application/json',
'Content-Type': 'application/json'
,
body: JSON.stringify(
client_id: 'XXXXXX',
client_secret: 'XXXXXX',
grant_type: 'authorization_code',
redirect_uri: 'XXXXXX',
code: 'XXXXXX'
),
)
.then(res => res.json())
.then(obj =>
console.error(obj);
)
.catch((error) =>
console.error(error);
)
And I keep getting a response of You must provide a client_id.
I tried to create a jQuery code of this request which DOES WORK.
$.ajax(
type: "POST",
url: "https://api.instagram.com/oauth/access_token",
data:
client_id: 'XXXXXX',
client_secret: 'XXXXXX',
grant_type: 'authorization_code',
redirect_uri: 'XXXXXX',
code: 'XXXXXX'
,
success: function(html)
console.error(html)
,
error: function(html)
console.error(html)
);
A one liner ruby code which also DOES WORK
Net::HTTP.post_form(URI.parse('https://api.instagram.com/oauth/access_token'), 'client_id': 'XXXXXX','client_secret': 'XXXXXX','grant_type': 'authorization_code','redirect_uri': 'XXXXXX','code': 'XXXXXX').body
Can you seem to spot what is wrong with my code? It does work with jQuery.
javascript ajax react-native
According to Instagram API to this is a sample request to get access_token
.
curl -F 'client_id=XXXXXX'
-F 'client_secret=XXXXXX'
-F 'grant_type=authorization_code'
-F 'redirect_uri=XXXXXX'
-F 'code=XXXXXX'
https://api.instagram.com/oauth/access_token
If I run this in the terminal I can get a result that looks something like this:
"access_token": "fb2e77d.47a0479900504cb3ab4a1f626d174d2d",
"user":
"id": "1574083",
"username": "snoopdogg",
"full_name": "Snoop Dogg",
"profile_picture": "..."
The problem is that it doesn't work with react-native.
I am using this code to make a post request on react-native:
fetch('https://api.instagram.com/oauth/access_token',
method: 'POST',
headers:
'Accept': 'application/json',
'Content-Type': 'application/json'
,
body: JSON.stringify(
client_id: 'XXXXXX',
client_secret: 'XXXXXX',
grant_type: 'authorization_code',
redirect_uri: 'XXXXXX',
code: 'XXXXXX'
),
)
.then(res => res.json())
.then(obj =>
console.error(obj);
)
.catch((error) =>
console.error(error);
)
And I keep getting a response of You must provide a client_id.
I tried to create a jQuery code of this request which DOES WORK.
$.ajax(
type: "POST",
url: "https://api.instagram.com/oauth/access_token",
data:
client_id: 'XXXXXX',
client_secret: 'XXXXXX',
grant_type: 'authorization_code',
redirect_uri: 'XXXXXX',
code: 'XXXXXX'
,
success: function(html)
console.error(html)
,
error: function(html)
console.error(html)
);
A one liner ruby code which also DOES WORK
Net::HTTP.post_form(URI.parse('https://api.instagram.com/oauth/access_token'), 'client_id': 'XXXXXX','client_secret': 'XXXXXX','grant_type': 'authorization_code','redirect_uri': 'XXXXXX','code': 'XXXXXX').body
Can you seem to spot what is wrong with my code? It does work with jQuery.
javascript ajax react-native
javascript ajax react-native
edited Mar 8 at 2:35
David Angulo
asked Mar 8 at 2:24
David AnguloDavid Angulo
660422
660422
Try your request withFormData
? Cause that what-F
oncurl
means. This SO answer explains how
– wicky
Mar 8 at 2:34
Where did you callfetch
method? Follow this example facebook.github.io/react-native/docs/network .Remember toreturn
it insidecomponentDidMount
– Vu Luu
Mar 8 at 2:34
@VuLuu I am calling it insidecomponentDidMount()
.
– David Angulo
Mar 8 at 2:37
Please replace yourfetch
content by:fetch('https://jsonplaceholder.typicode.com/todos/1') .then(response => response.json()) .then(json => console.log(json))
Is it work?
– Vu Luu
Mar 8 at 2:38
@VuLuu Yes get request does work. Also my request to Instagram goes through the only problem is that the parameters does not get passed.
– David Angulo
Mar 8 at 2:41
|
show 4 more comments
Try your request withFormData
? Cause that what-F
oncurl
means. This SO answer explains how
– wicky
Mar 8 at 2:34
Where did you callfetch
method? Follow this example facebook.github.io/react-native/docs/network .Remember toreturn
it insidecomponentDidMount
– Vu Luu
Mar 8 at 2:34
@VuLuu I am calling it insidecomponentDidMount()
.
– David Angulo
Mar 8 at 2:37
Please replace yourfetch
content by:fetch('https://jsonplaceholder.typicode.com/todos/1') .then(response => response.json()) .then(json => console.log(json))
Is it work?
– Vu Luu
Mar 8 at 2:38
@VuLuu Yes get request does work. Also my request to Instagram goes through the only problem is that the parameters does not get passed.
– David Angulo
Mar 8 at 2:41
Try your request with
FormData
? Cause that what -F
on curl
means. This SO answer explains how– wicky
Mar 8 at 2:34
Try your request with
FormData
? Cause that what -F
on curl
means. This SO answer explains how– wicky
Mar 8 at 2:34
Where did you call
fetch
method? Follow this example facebook.github.io/react-native/docs/network .Remember to return
it inside componentDidMount
– Vu Luu
Mar 8 at 2:34
Where did you call
fetch
method? Follow this example facebook.github.io/react-native/docs/network .Remember to return
it inside componentDidMount
– Vu Luu
Mar 8 at 2:34
@VuLuu I am calling it inside
componentDidMount()
.– David Angulo
Mar 8 at 2:37
@VuLuu I am calling it inside
componentDidMount()
.– David Angulo
Mar 8 at 2:37
Please replace your
fetch
content by: fetch('https://jsonplaceholder.typicode.com/todos/1') .then(response => response.json()) .then(json => console.log(json))
Is it work?– Vu Luu
Mar 8 at 2:38
Please replace your
fetch
content by: fetch('https://jsonplaceholder.typicode.com/todos/1') .then(response => response.json()) .then(json => console.log(json))
Is it work?– Vu Luu
Mar 8 at 2:38
@VuLuu Yes get request does work. Also my request to Instagram goes through the only problem is that the parameters does not get passed.
– David Angulo
Mar 8 at 2:41
@VuLuu Yes get request does work. Also my request to Instagram goes through the only problem is that the parameters does not get passed.
– David Angulo
Mar 8 at 2:41
|
show 4 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55055837%2freact-native-fetch-post-request-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55055837%2freact-native-fetch-post-request-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try your request with
FormData
? Cause that what-F
oncurl
means. This SO answer explains how– wicky
Mar 8 at 2:34
Where did you call
fetch
method? Follow this example facebook.github.io/react-native/docs/network .Remember toreturn
it insidecomponentDidMount
– Vu Luu
Mar 8 at 2:34
@VuLuu I am calling it inside
componentDidMount()
.– David Angulo
Mar 8 at 2:37
Please replace your
fetch
content by:fetch('https://jsonplaceholder.typicode.com/todos/1') .then(response => response.json()) .then(json => console.log(json))
Is it work?– Vu Luu
Mar 8 at 2:38
@VuLuu Yes get request does work. Also my request to Instagram goes through the only problem is that the parameters does not get passed.
– David Angulo
Mar 8 at 2:41