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?













0















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.










share|improve this question
























  • 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











  • @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















0















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.










share|improve this question
























  • 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











  • @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













0












0








0








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 2:35







David Angulo

















asked Mar 8 at 2:24









David AnguloDavid Angulo

660422




660422












  • 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











  • @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

















  • 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











  • @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
















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












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
);



);













draft saved

draft discarded


















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















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme