question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to send Raw http for Instagram Authentication?

See original GitHub issue

I’m trying to connect to the Instagram API with axios.

Here’s my code:

axios( {
    method: 'POST',
    url: '/oauth/access_token',
    baseURL: 'https://api.instagram.com',
    params: { // both data and params don't work
        'client_id': 'CLIENT_ID',
        'client_secret': 'CLIENT_SECRET',
        'grant_type': 'authorization_code',
        'redirect_uri': 'REDIRECT_URI',
        'code': 'CODE',
    },
} )

I keep getting the response No client_id so it’s not reading any of the params.

When I use restify’s StringClient

return new Promise( function ( resolve, reject ) {
    client.post( '/oauth/access_token', {
        'client_id': 'CLIENT_ID',
        'client_secret': 'CLIENT_SECRET',
        'grant_type': 'authorization_code',
        'redirect_uri': 'REDIRECT_URI',
        'code': 'CODE',
    }, function ( errr, reqq, ress, dataa ) {
        if ( errr ) {
            reject( errr )
        } else {
            resolve( dataa )
        }
    } )
} )

It works great.

I think it has something to do with application/x-www-form-urlencoded header maybe?

I would like to know how I can get this working with axios. Thank you!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:17 (4 by maintainers)

github_iconTop GitHub Comments

205reactions
nickuraltsevcommented, Jun 20, 2016

Yes, StringClient uses the application/x-www-form-urlencoded format by default while axios uses application/json by default (when data is an Object).

Here is how to make an application/x-www-form-urlencoded request with axios:

Browser

var qs = require('qs');
axios.post('/foo', qs.stringify({ 'bar': 123 });

Node

You can use querystring module to encode the data:

var querystring = require('querystring');

axios.post('/foo', querystring.stringify({
  'bar': 123
});

Hope this helps!

7reactions
BitOfGoldcommented, Feb 16, 2018

You can patch axios to use application/x-www-form-urlencoded Solution here: https://github.com/axios/axios/issues/97


axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
axios.defaults.transformRequest = [function (data, headers) {
    var str = [];
    for(var p in data)
      if (data.hasOwnProperty(p) && data[p]) {
        str.push(encodeURIComponent(p) + "=" + encodeURIComponent(data[p]));
      }
    return str.join("&");
  }];
Read more comments on GitHub >

github_iconTop Results From Across the Web

Turn on two-factor authentication
Two-factor authentication is a security feature that helps protect your Instagram account ... Text message: We'll send a login code to your mobile...
Read more >
PHP How To Send Raw HTTP Packet
im trying to emulate the raw packets that i captured using wireshark. but i keep getting "auth needed" or "request denied" responses :(...
Read more >
windows - utility program for issuing raw HTTP commands?
Sends some data via POST, as well as some arguments via GET to a specific URL. -q means don't give me progress updates,...
Read more >
HTTP Headers for Dummies - Code - Envato Tuts+
POST : Send Data to the Server · The path in the first line is simply /foo.php , and there is no query...
Read more >
Unsplash API Documentation | Free HD Photo API
The Unsplash API uses HTTP verbs appropriate to each action. ... raw returns a base image URL with just the photo path and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found