phpnode.jshttprequestdeezer

Deezer API access token


I've tried to get my access token for the deezer API but i keep getting the 'wrong code' message when i send my request. Here is the said request :

'https://connect.deezer.com/oauth/access_token.php?app_id=' + appID + '&secret=' + clientSecret + '&code=' + code;

The app ID and the client secret are located on developers.deezer.com/myapps so i can't be wrong with these two.

For the code i'm using a php code sample given by deezer themself (you can look it up here : https://developers.deezer.com/api/oauth) The said sample code is a simple page that makes you agree to let your application your data, as usual. At the end you're redirected to an empty page with an url like this one (don't worry, the code and scope are fake) :

http://localhost/deezerAPI/test1.php?code=fr14364f27b39760284c5698&state=27f24b97ab810mb3176d42fh

Anyway, I've copy and pasted the (fake) code fr14364f27b39760284c5698 to a self made node js program (why nodejs? because i'm much more comfortable using node to send requests) (also, the values here are fake too) :

'use strict';

const express = require('express');
var request = require('request');

const app = new express();

var appID = '<appId>'
var clientSecret = '<clientSecret>';
var code = 'fr14364f27b39760284c5698'

var requestURI = 'https://connect.deezer.com/oauth/access_token.php?app_id=' + appID + '&secret=' + clientSecret + '&code=' + code;

request(requestURI, (error, response, body) => {
  console.log("Recieved body'" + body + "'");
});

app.listen(8081, () => {
    console.log("WebClient is up!");
});

And every time i recieve the body 'wrong code'. To me it can only mean two things :

PS: if you want to see the deezer code sample tell me, what i have on my wamp server isn't different from what they have but maybe you'll see something that doesn't add up.


Solution

  • STEP 1

       https://connect.deezer.com/oauth/auth.php?app_id=YOUR_APP_ID&redirect_uri=YOUR_REDIRECT_URI&perms=basic_access,email
    

    STEP 2

    https://connect.deezer.com/oauth/access_token.php?app_id=YOU_APP_ID&secret=YOU_APP_SECRET&code=THE_CODE_FROM_ABOVE