PhantomJS和SoundCloud嵌入

时间:2015-08-01 21:15:44

标签: phantomjs soundcloud

我正在构建一个依赖Soundcloud的应用程序。 每当我加载此页面时,Soundcloud事件的所有postMessages都具有值null。

我的端点如下所示,http://localhost:3000/rap/video/157681

实施例中,

当我附上这个片段时,我可以看到发生了什么。

page.onConsoleMessage = function(msg) {
  console.log(msg);
};

这显示了以下内容:

received message {"widgetId":"widget_1438463010590","method":"getDuration","value":null} from https://w.soundcloud.com
received message {"widgetId":"widget_1438463010590","method":"ready","value":null} from https://w.soundcloud.com
received message {"widgetId":"widget_1438463010590","method":"error","value":null} 
from https://w.soundcloud.com

当我不使用PhantomJS时,我没有遇到这个问题。 (即如果我使用Chrome加载相同的端点)。

预期的响应看起来像这样(这是我在真实浏览器中运行时得到的结果)。

received message {"widgetId":"widget_1438462797950","method":"getDuration","value":46528} from https://w.soundcloud.com
received message {"widgetId":"widget_1438462797950","method":"getCurrentSound","value":{"id":215298719,"resource_type":"sound","playable":true,"kind":"track","created_at":"2015/07/18 18:48:55 +0000","user_id":156179640,"duration":46528,"commentable":true,"state":"finished","original_content_size":8194532,"last_modified":"2015/07/18 18:49:04 +0000","sharing":"public","tag_list":"CGY Calgary Stampede Wild Rap Hiphop Rappad","permalink":"wild-west","streamable":true,"embeddable_by":"all","downloadable":false,"purchase_url":null,"label_id":null,"purchase_title":null,"genre":null,"title":"Wild West","description":null,"label_name":null,"release":null,"track_type":"recording","key_signature":null,"isrc":null,"video_url":null,"bpm":null,"release_year":null,"release_month":null,"release_day":null,"original_format":"wav","license":"cc-by","uri":"https://api.soundcloud.com/tracks/215298719","user":{"id":156179640,"kind":"user","permalink":"nxplicit","username":"Erik Soby","last_modified":"2015/07/29 15:40:17 +0000","uri":"https://api.soundcloud.com/users/156179640","permalink_url":"https://soundcloud.com/nxplicit","avatar_url":"https://i1.sndcdn.com/avatars-000155555549-4ur1q9-large.jpg"},"created_with":{"id":45176,"kind":"app","name":"Ableton Live","uri":"https://api.soundcloud.com/apps/45176","permalink_url":"http://soundcloud.com/apps/ableton-live","external_url":"http://www.ableton.com/free-trial"},"permalink_url":"https://soundcloud.com/nxplicit/wild-west","artwork_url":null,"waveform_url":"https://w1.sndcdn.com/kMqYHwA5fBzl_m.png","stream_url":"https://api.soundcloud.com/tracks/215298719/stream","playback_count":310,"download_count":0,"favoritings_count":0,"comment_count":0,"likes_count":0,"reposts_count":0,"attachments_uri":"https://api.soundcloud.com/tracks/215298719/attachments","policy":"ALLOW","monetization_model":"NOT_APPLICABLE","publisher_info":{},"_resource_id":215298719,"_resource_type":"sound"}} from https://w.soundcloud.com

取得一些进展

我将此片段添加到PhantomJS中,我能够得到结果。

page.evaluate(function() {
  var widget = SC.Widget('ui-id-1')
  widget.getDuration(function(callback) {
    console.log('getDuration called');
    console.log(callback);
  });
});

在命令行中返回

getDuration called
46528
received message {"widgetId":"widget_1438464901479","method":"getDuration","value":46528} from https://w.soundcloud.com

所以也许问题根本不在于Soundcloud。

0 个答案:

没有答案