Utilizing Soundcloud API Authentication in Angular.js: A Step-by-Step Guide

I've been able to successfully use the public Soundcloud API, but I'm struggling with implementing the callback.html in order to display the login dialog.

For my App on Soundcloud, the callback redirect uri is set to: http://localhost:8080/#/callback

On this route, my angular app defines a Controller with the desired callback template:

<!DOCTYPE html>
<html lang="en">
    <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Connect with SoundCloud</title>
    </head>
    <body onload="window.opener.setTimeout(window.opener.SC.connectCallback, 1)">
        <b style="width: 100%; text-align: center;">This popup should automatically close in a few seconds</b>
    </body>
</html>

In my root controller, I have already initialized the API:

SC.initialize({
    client_id: "####",
    redirect_uri: "http://localhost:8080/#/callback",
});

This setup allows me to successfully make requests to the public API in other controllers like so:

SC.get('/resolve', {
     url: 'https://soundcloud.com/someuser'
}, function(user) {
    console.log(user);
});

However, when trying to retrieve data about the authenticated user using the same Controller, I receive a 401 error:

SC.get('/me', function(me) {
    console.log(me);
});

It's clear that there is no login dialog popping up. So, what am I missing in setting up the callback.html?

Some assumptions I have made are:

  1. Could it be due to the presence of /#/ in the URL? I tried using <base href="/"> and

    $locationProvider.html5Mode(true);
    but saw no change.

  2. Maybe the callback.html should not be served within the SPA environment, but as an independent static page?

  3. Is there a mapping issue with the callback.html?

  4. I'm using webpack as a build tool. Could there be an issue related to that?

  5. Do I need to configure something else besides the redirect uri in my Soundcloud App settings?

I really hope someone can assist me with this issue!

Answer №1

My website also utilizes AngularJS and SoundCloud integration. I noticed that the SC.connect function is missing in your code, is it located elsewhere?

This is the function in my controller:

this.connect= function(){

            SC.connect(function(response){

                SC.get("/me", function(response){
                    // console.log(response);
                    var data={};
                    data.token = SC.accessToken();
                    data.id = response.id;
                    $rootScope.user.sc_id=data.id;
                    $rootScope.user.sc_token=data.token;
                    soundcloud.saveToken(data);
                    soundcloud.generateAuthString();

                    //other things

        });
    });

 }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Why is my Bootstrap Carousel Switching Images but Refusing to Slide?

I've encountered a problem with my bootstrap carousel. The slide effect doesn't seem to be working, even though I have added the "slide" CSS tag. Instead of sliding, the images just quickly change without any transition. Here are some key points ...

What could be the reason for the undefined value of my ID retrieved from the next JS router.query upon page refresh?

When using the id obtained from the next router.query to dynamically render elements, it works fine when accessing the room from next/link. However, upon refreshing the page, an error is thrown. https://i.stack.imgur.com/yEjGS.png Below is the code snipp ...

Using AngularJS's $watchCollection in combination with ng-repeat

Encountering difficulties receiving notifications for changes in a list when utilizing an input field within ng-repeat directly. However, I am able to modify values and receive notifications from $watchCollection. To illustrate: <!DOCTYPE html> < ...

Issue with offset calculation in bootstrap table occurs when the bootstrap-table is closed and the window is resized

In a recent project, I utilized the bootstrap table. However, upon closing the bootstrap table with the following script: $(document).ready(function () { $(".removetable").click(function (e) { $(".table-aria").remove(); ...

Discovering elements within an array JSON using Angular JS: A complete guide

The API call response is in JSON format: [ { "RESULT": { "TYPES": [ "bigint", "varchar", "varchar", "varchar", "varchar", "varchar", "date", "varch ...

The drop-down list was designed with a main button to activate it, but for some reason it is not functioning properly. Despite numerous attempts, the list simply will not display as intended

<html> <body> <button onclick="toggle()" class="nm" > main</button> <div class="cntnr" style="display : none;"> <ul class="cnkid"> <li class="cnkid"><a class="cnkid" ...

Unable to display PHP response in a div using AJAX - issue persisting

Hey there! I'm currently working on a project where I want the form submission to load a response into a div without refreshing the page. I've looked at various examples of ajax forms with PHP online, but haven't been able to solve my issue ...

Using jQuery to replace the content of a div with a delay?

I am attempting to utilize jQuery to create a fade effect on an element, replace its innerHTML content, and then fade it back in once the new content has been added. I have successfully managed to replace the element's content using the .html() method ...

Tips for maintaining the original Backbone template when reloading the browser

Within my Backbone application (with a Rails backend), I utilize [Handlebars] JavaScript templates (JST's) to render the Backbone views. However, whenever I refresh the browser while on a URL template, it always redirects me back to the root URL. I am ...

The search function on my blog is not displaying the blogs that have been filtered

I have encountered an issue with my code as I am unable to get any search results from the search bar. const RecentBlogs = ({recentBlogs}) => { const [query, setQuery] = useState("") const filteredItems = (() => { if(!query) return rec ...

The error message "THREE is not defined" indicates a problem

Hey there! I've been experimenting with running some three.js examples on my local machine. I ran into some security issues, so I set up a local server using Python. While the background image and text appear as expected, the animations are not workin ...

Utilizing libraries in JavaScript

For a while now, I've been grappling with an issue related to importing modules into my main JavaScript script. I recently installed the lodash library via npm and I'm trying to import it into my main script so that I can utilize its functionali ...

The Ajax PHP file uploader is experiencing technical difficulties

I am currently working on an ajax image uploader that is supposed to work automatically when a user submits an image. However, I've encountered an issue where the uploader does not function as expected when I try to rename the images for ordering purp ...

The iPad screen displays the image in a rotated position while it remains

Recently, I developed a mini test website that enables users to upload pictures and immediately see them without navigating back to the server. It seemed quite simple at first. $('input').on('change', function () { var file = this. ...

Implementing Dropzone in an Angular MVC5 project

For more information about dropzone, visit this link I am currently implementing dropzone as my file upload handler with the combination of angularjs and MVC5. The challenge I'm facing is getting the Http post request to go from the angularjs servic ...

Can someone explain the process of adding a JavaScript state variable from one React component so that it can be utilized in other components?

In my Home.js component, I handle user sign up to the API and login. After receiving the token from the authorization header in the response, I save it in the state variable 'token'. This token is crucial for accessing the API in other component ...

Verify the presence of a particular attribute in an HTML tag using Capybara and polling techniques

In my HTML code, the attributes of buttons (such as "AAAAA") will change based on external events. This real-time update is achieved through AJAX pooling. <div class="parent"> <div class="group"><button title="AAAAA"/></div> <di ...

Difficulty with Angular's Interpolation and incorporating elements

I've encountered an issue with String Interpolation while following an Angular course. In my server.component.ts file, I've implemented the same code as shown by the teacher in the course: import { Component } from "@angular/core"; @Component ( ...

Issue with displaying errors in vee-validate when using Vue.js Axios (More details provided)

When working on my Vue project, I encountered an issue while using Vee-Validate and Axios. During an API call to register a user, if the email is already in use, an error is thrown. To handle this error and display the error message, I used the following ...

Load components dynamically and place them in a flexible position based on the context

UPDATE (After gaining a better understanding of the issue): I'm trying to display a component based on where the user clicks (specifically, which table row). Using ng2-smart-table, I've encountered an issue where there isn't a suitable sele ...