PubNub Twitter 数据流设置没有 return 数据
PubNub Twitter Data Stream setup doesn't return data
尝试用 D3 将推文映射到世界地图上,并首次使用 PubNub 获取实时数据流。设置时遇到问题并得到以下代码:
var margin = {top: 20, right: 20, bottom: 20, left: 20};
var w = 1100 - margin.left - margin.right,
h = 900 - margin.top - margin.bottom;
var svg = d3.select("#chart")
.append("svg")
.attr("width", w + margin.left + margin.right)
.attr("height", h + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var geoData = "https://raw.githubusercontent.com/johan/world.geo.json/master/countries.geo.json";
d3.json(geoData, function(data){
var geo = data.features;
var projection = d3.geo.mercator()
.scale(150)
.translate([w/2,h/2]);
var path = d3.geo.path()
.projection(projection);
svg.selectAll("path")
.data(geo)
.enter()
.append("path")
.attr("fill", "#95E1D3")
.attr("stroke", "#34495e")
.attr("stroke-width", 0.5)
.attr("class", function(d){ return d.properties.name})
.attr("d", path);
var pubnub = new PubNub({
subscribeKey : "my key"
});
pubnub.subscribe({
channels: ['pubnub-twitter'],
withPresence: true
});
pubnub.addListener({
message: function(m) {
console.log(m);
},
presence: function(p){
console.log(p);
},
status: function(s){
console.log(s);
}
})
})
我希望它将消息打印到控制台,但没有任何反应。使用 PubNub v4。有人可以帮我吗?
这是一个可用的代码笔:
Twitter 示例提要流式推文
以下示例将在 console.log()
中打印所有推文。您可以通过单击 "Run code snippet" 按钮自行测试。您将在控制台中看到一连串推文。
// Create PubNub Socket Handler
const pubnub = new PubNub({
publishKey : 'empty'
, ssl : true
, subscribeKey : 'sub-c-78806dd4-42a6-11e4-aed8-02ee2ddab7fe'
});
// Subscribe to Twitter feed
console.log("Subscribing to Live Twitter Stream.");
pubnub.subscribe({ channels: ['pubnub-twitter'] });
// Add Socket Event Function Handlers
pubnub.addListener({
status : statusEvent => console.log(statusEvent)
, message : message => console.log(message)
});
<script src="https://cdn.pubnub.com/sdk/javascript/pubnub.4.4.2.min.js"></script>
PubNub 在 2014 年发布了一篇博客,展示了 how to analyze tweets from Twitter's Firehose。
尝试用 D3 将推文映射到世界地图上,并首次使用 PubNub 获取实时数据流。设置时遇到问题并得到以下代码:
var margin = {top: 20, right: 20, bottom: 20, left: 20};
var w = 1100 - margin.left - margin.right,
h = 900 - margin.top - margin.bottom;
var svg = d3.select("#chart")
.append("svg")
.attr("width", w + margin.left + margin.right)
.attr("height", h + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var geoData = "https://raw.githubusercontent.com/johan/world.geo.json/master/countries.geo.json";
d3.json(geoData, function(data){
var geo = data.features;
var projection = d3.geo.mercator()
.scale(150)
.translate([w/2,h/2]);
var path = d3.geo.path()
.projection(projection);
svg.selectAll("path")
.data(geo)
.enter()
.append("path")
.attr("fill", "#95E1D3")
.attr("stroke", "#34495e")
.attr("stroke-width", 0.5)
.attr("class", function(d){ return d.properties.name})
.attr("d", path);
var pubnub = new PubNub({
subscribeKey : "my key"
});
pubnub.subscribe({
channels: ['pubnub-twitter'],
withPresence: true
});
pubnub.addListener({
message: function(m) {
console.log(m);
},
presence: function(p){
console.log(p);
},
status: function(s){
console.log(s);
}
})
})
我希望它将消息打印到控制台,但没有任何反应。使用 PubNub v4。有人可以帮我吗?
这是一个可用的代码笔:
Twitter 示例提要流式推文
以下示例将在 console.log()
中打印所有推文。您可以通过单击 "Run code snippet" 按钮自行测试。您将在控制台中看到一连串推文。
// Create PubNub Socket Handler
const pubnub = new PubNub({
publishKey : 'empty'
, ssl : true
, subscribeKey : 'sub-c-78806dd4-42a6-11e4-aed8-02ee2ddab7fe'
});
// Subscribe to Twitter feed
console.log("Subscribing to Live Twitter Stream.");
pubnub.subscribe({ channels: ['pubnub-twitter'] });
// Add Socket Event Function Handlers
pubnub.addListener({
status : statusEvent => console.log(statusEvent)
, message : message => console.log(message)
});
<script src="https://cdn.pubnub.com/sdk/javascript/pubnub.4.4.2.min.js"></script>
PubNub 在 2014 年发布了一篇博客,展示了 how to analyze tweets from Twitter's Firehose。