SoundCloud API 数据在调试器中检索到,但仅在 运行 时检索不到
SoundCloud API data is retrieved in debugger but not when just run
我正在尝试使用 SoundCloud 的可用功能 API 提取用户数据。当我 运行 代码时,LocalStorage 中什么也没有出现;然而,当我通过调试器 运行 代码时,所有必要的键值都会生成并添加到 LocalStorage。
$(document).ready(function() {
SC.initialize({
client_id: '40b9cd8db2848eedd9dce3381b51916f',
redirect_uri: 'http://localhost:8000/callback.html'
});
$('.btn-instagram').click(function(){
SC.connect(function() {
SC.get('/me', function(data) {
var userData = {"id": data.id, "username": data.username, "permalink_url": data.permalink_url, "avatar_url": data.avatar_url, "full_name": data.full_name, "country": data.country, "city": data.city, "description": data.description, "track_count": data.track_count, "followers_count": data.followers_count, "followings_count": data.followings_count, "private_tracks_count": data.private_tracks_count}
localStorage.setItem('userData', JSON.stringify(userData));
SC.get('/users/' + data.id + '/tracks/', function(tracks) {
for (var i = 0; i < tracks.length; i++) {
console.log(tracks[i].title);
localStorage.setItem(tracks[i].title, JSON.stringify({"id": tracks[i].id, "title": tracks[i].title, "permalink_url": tracks[i].permalink_url, "artwork_url": tracks[i].artwork_url, "label_name": tracks[i].label_name, "release_day": tracks[i].release_day, "release_month": tracks[i].release_month, "release_year": tracks[i].release_year, "comment_count": tracks[i].comment_count, "download_count": tracks[i].download_count, "playback_count": tracks[i].playback_count, "favoritings_count": tracks[i].favoritings_count}))
}
});
});
window.location = "dashboardindex.html";
});
});
});
想通了。按钮点击功能给我带来了问题。
我正在尝试使用 SoundCloud 的可用功能 API 提取用户数据。当我 运行 代码时,LocalStorage 中什么也没有出现;然而,当我通过调试器 运行 代码时,所有必要的键值都会生成并添加到 LocalStorage。
$(document).ready(function() {
SC.initialize({
client_id: '40b9cd8db2848eedd9dce3381b51916f',
redirect_uri: 'http://localhost:8000/callback.html'
});
$('.btn-instagram').click(function(){
SC.connect(function() {
SC.get('/me', function(data) {
var userData = {"id": data.id, "username": data.username, "permalink_url": data.permalink_url, "avatar_url": data.avatar_url, "full_name": data.full_name, "country": data.country, "city": data.city, "description": data.description, "track_count": data.track_count, "followers_count": data.followers_count, "followings_count": data.followings_count, "private_tracks_count": data.private_tracks_count}
localStorage.setItem('userData', JSON.stringify(userData));
SC.get('/users/' + data.id + '/tracks/', function(tracks) {
for (var i = 0; i < tracks.length; i++) {
console.log(tracks[i].title);
localStorage.setItem(tracks[i].title, JSON.stringify({"id": tracks[i].id, "title": tracks[i].title, "permalink_url": tracks[i].permalink_url, "artwork_url": tracks[i].artwork_url, "label_name": tracks[i].label_name, "release_day": tracks[i].release_day, "release_month": tracks[i].release_month, "release_year": tracks[i].release_year, "comment_count": tracks[i].comment_count, "download_count": tracks[i].download_count, "playback_count": tracks[i].playback_count, "favoritings_count": tracks[i].favoritings_count}))
}
});
});
window.location = "dashboardindex.html";
});
});
});
想通了。按钮点击功能给我带来了问题。