Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

401 - Unauthorized on POST request to '/tracks' route #8

Open
tryenc opened this issue Apr 20, 2016 · 6 comments
Open

401 - Unauthorized on POST request to '/tracks' route #8

tryenc opened this issue Apr 20, 2016 · 6 comments

Comments

@tryenc
Copy link

tryenc commented Apr 20, 2016

I'm getting a 401 - Unauthorized on POST request to the '/tracks' route. I'm trying to upload a track to my Soundcloud profile. Any idea why this wouldn't be working? Thanks so much in advance!

        var SC = require('node-soundcloud');

        SC.init({
            id: client_id, 
            secret: client_secret, 
            uri: redirect_uri,
            accessToken: access_token
        });

        var mp3Path = path.join(__dirname + '../../../test2.mp3')

        SC.post('/tracks', {
            track: {
                'asset_data': fs.createReadStream(mp3Path),
                'title': '4.20-14.47'
            }
        }, function(err, data){
            console.log("data", data);
            res.end();
        })
@jakemmarsh
Copy link
Owner

According to their API documentation, the key for the actual file should be file and not asset_data: https://developers.soundcloud.com/docs/api/guide#uploading

Is there a reason you're using asset_data?

@tryenc
Copy link
Author

tryenc commented Apr 20, 2016

Hey Jake,

Thanks for getting back so fast. I was using 'asset_data' because that's what the API Reference says to use for a request to '/tracks'. The 'asset_data' property is at the very bottom of the '/tracks' section. Regardless, I tried issuing the same post using 'file' in place of 'asset_data' and I got the same error.

Thanks again for the fast response. I'm really looking forward to getting this solved.

@jakemmarsh
Copy link
Owner

Ah, okay. How are you retrieving your access_token?

@tryenc
Copy link
Author

tryenc commented Apr 20, 2016

Utilizing the JavaScript SDK inside of an Angular controller. The SDK is requested in a script tag in the HTML. If I upload with the SDK from the front-end it's working.

app.controller('SoundcloudController', ['$scope', 'SoundcloudService', function($scope, SoundcloudService){

  SC.initialize({
    client_id: 'somefakecilentid',
    redirect_uri: 'http://localhost:1337/callback.html',
    display: 'popup'
  });

  $scope.song = {};

  $scope.upload = function(){ 

    var fd = new FormData();
    fd.append('file', $scope.song.file);
    fd.append('title', $scope.song.title);

    SC.connect({
      scope: 'non-expiring',
      response_type: 'token'
    })
//================ UPLOAD FROM FRONT-END ================

    // .then(function(){
  
    //   return SC.upload({
    //     file: $scope.song.file,
    //     title: $scope.song.title
    //   })
    // })
    // .then(function(track){
    //   console.log("track", track);
    // })

//========== UPLOAD FROM BACK-END WITH SERVICE ==========

    .then(function(res){
      console.log("res.oauth_token", res.oauth_token);
      return fd.append('accessToken', res.oauth_token);
    })
    .then(function(){  
      return SoundcloudService.uploadFile(fd);
    })   
    .then(function(res){
      console.log("res", res);
    })

  };

}]);

@akatrodiya
Copy link

Hey Guys!

I'm getting the same error and I'm following the same method which Tryenc has used..
is there any resolution for this?

Thank you!

@TheMSB
Copy link

TheMSB commented Sep 14, 2016

I'm running into something similar too, I'm using the connect screen authentication to get a token but any subsequent requests return a 401.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants