axios: status: 400, statusText: 'Bad Request'
I keep getting this response when using Axios to get an access token from Instagram.
My Code: `async function mintAuthToken(req: any): Promise<string> { const base = ‘https://api.instagram.com/oauth/access_token’;
const queryParams = {
client_id: app_id,
client_secret: app_secret,
grant_type: 'authorization_code',
redirect_uri: redirect_uri,
code: req.query.code
}
const endpoint = base + qs.stringify( queryParams )
const login = await axios.post(endpoint, {},{headers: {'content-type': 'application/json'}}
);
console.log(login);
const accessToken = login.data.access_token;
const instagramUserID = login.data.user.id;
const profilePic = login.data.user.profile_picture;
const userName = login.data.user.full_name;
console.log(userName);
const firebaseToken = await createFirebaseAccount(instagramUserID, userName, profilePic, accessToken);
return firebaseToken;
};`
The full error:
{ status: 400, statusText: 'Bad Request', headers: { 'content-type': 'text/html; charset=utf-8', vary: 'Accept-Language', 'content-language': 'en', date: 'Fri, 17 Jan 2020 22:16:38 GMT, Fri, 17 Jan 2020 22:16:38 GMT', 'strict-transport-security': 'max-age=31536000', 'cache-control': 'private, no-cache, no-store, must-revalidate', pragma: 'no-cache', expires: 'Sat, 01 Jan 2000 00:00:00 GMT', 'x-frame-options': 'SAMEORIGIN', 'content-security-policy': 'report-uri https://www.instagram.com/security/csp_report/; default-src \'self\' https://www.instagram.com; img-src https: data: blob:; font-src https: data:; media-src \'self\' blob: https://www.instagram.com https://*.cdninstagram.com https://*.fbcdn.net; manifest-src \'self\' https://www.instagram.com; script-src \'self\' https://instagram.com https://www.instagram.com https://*.www.instagram.com https://*.cdninstagram.com wss://www.instagram.com https://*.facebook.com https://*.fbcdn.net https://*.facebook.net \'unsafe-inline\' \'unsafe-eval\' blob:; style-src \'self\' https://*.www.instagram.com https://www.instagram.com \'unsafe-inline\'; connect-src \'self\' https://instagram.com https://www.instagram.com https://*.www.instagram.com https://graph.instagram.com https://*.graph.instagram.com https://*.cdninstagram.com https://api.instagram.com wss://www.instagram.com wss://edge-chat.instagram.com https://*.facebook.com https://*.fbcdn.net https://*.facebook.net chrome-extension://boadgeojelhgndaghljhdicfkmllpafd blob:; worker-src \'self\' blob: https://www.instagram.com; frame-src \'self\' https://instagram.com https://www.instagram.com https://staticxx.facebook.com https://www.facebook.com https://web.facebook.com https://connect.facebook.net https://m.facebook.com; object-src \'none\'; upgrade-insecure-requests', 'x-content-type-options': 'nosniff', 'x-xss-protection': '0', 'x-aed': '15', 'access-control-expose-headers': 'X-IG-Set-WWW-Claim', 'set-cookie': [ 'ig_did=D9E1610B-B50C-4A35-9B7B-6BF0C06AE976; Domain=.instagram.com; expires=Mon, 14-Jan-2030 22:16:38 GMT; HttpOnly; Max-Age=315360000; Path=/; Secure', 'rur=FTW; Domain=.instagram.com; HttpOnly; Path=/; Secure' ], 'x-fb-trip-id': '917726464', connection: 'close', 'content-length': '11' }, config: { url: 'https://api.instagram.com/oauth/access_tokenclient_id=client id&client_secret=secret&grant_type=authorization_code&redirect_uri=redirect&code=somecode', method: 'post', data: '{}', headers: { Accept: 'application/json, text/plain, */*', 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'axios/0.19.0', 'Content-Length': 2 }, transformRequest: [ [Function: transformRequest] ], transformResponse: [ [Function: transformResponse] ], timeout: 0, adapter: [Function: httpAdapter], xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN', maxContentLength: -1, validateStatus: [Function: validateStatus] }, request: ClientRequest { domain: Domain { domain: null, _events: [Object], _eventsCount: 1, _maxListeners: undefined, members: [Array] }, _events: { socket: [Function], abort: [Function], aborted: [Function], error: [Function], timeout: [Function], prefinish: [Function: requestOnPrefinish] }, _eventsCount: 6, _maxListeners: undefined, output: [], outputEncodings: [], outputCallbacks: [], outputSize: 0, writable: true, _last: true, upgrading: false, chunkedEncoding: false, shouldKeepAlive: false, useChunkedEncodingByDefault: true, sendDate: false, _removedConnection: false, _removedContLen: false, _removedTE: false, _contentLength: null, _hasBody: true, _trailer: '', finished: true, _headerSent: true, socket: TLSSocket { _tlsOptions: [Object], _secureEstablished: true, _securePending: false, _newSessionPending: false, _controlReleased: true, _SNICallback: null, servername: 'api.instagram.com', npnProtocol: undefined, alpnProtocol: false, authorized: true, authorizationError: null, encrypted: true, _events: [Object], _eventsCount: 9, connecting: false, _hadError: false, _handle: [Object], _parent: null, _host: 'api.instagram.com', _readableState: [Object], readable: true, domain: [Object],}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15
I also have the same problem with Axios and solved by using curl-request.
There’re a ton of problems with calling Instagram API using Axios on StackOverflow.
However, I still believe that Axios should be able to behave like cURL. Let’s see who could provide an equivalent solution in the short future…
I have checked with Instagram it works when I send a curl request it works but when I send it using axios in firebase cloud functions I am using stringify to string it all in the url