标签: twitter-streaming-api

Tweepy Streaming API为启用地理位置的推文上的坐标返回"无"

我正在使用Tweepy来访问流API.我可以使用下面的代码获得结果,但对于Geo Enabled值为"True"的推文,我得到的坐标返回值为"False".怎么会这样?我是否需要解码为status.coordinates返回的JSON对象?

from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
import random
import time
import MySQLdb
import json

consumer_key="XXX"
consumer_secret="XXX"

access_token="XXX"
access_token_secret="XXX"

db=MySQLdb.connect(host='localhost', user='XXX', passwd='XXX', db='twitter')
db.set_character_set('utf8')

Coords = dict()
Place = dict()
PlaceCoords = dict()
XY = []
curr=db.cursor()

class StdOutListener(StreamListener):
    """ A listener handles tweets that are the received from the stream.
    This is a basic listener that inserts tweets into MySQLdb.
    """
    def on_status(self, status):

        print "Tweet Text: ",status.text

        text = status.text

        print …
Run Code Online (Sandbox Code Playgroud)

python twitter tweepy twitter-streaming-api

2
推荐指数
1
解决办法
7063
查看次数

Twitter4j收听特定用户的推文

我想在特定用户推特的时候执行某些操作.那么在twitter4j中是否可以收听来自特定用户帐户的推文并处理该事件?

我知道答案是什么:阅读流式api.但我认为它对我来说太大了,我只想听一个特定账号的推文.我在这里问它.

java twitter4j twitter-streaming-api

2
推荐指数
1
解决办法
2522
查看次数

使用 Twitter API 发推文时出现重复状态错误

我是 JavaScript 新手,我正在使用 Node.js 和 Twitter API 作为学习编码的方式。我也在使用 Twit NPM 包。我正在尝试创建一个“游戏”,必须在推特上发布特定短语才能开始。我有一个功能,如果特定短语没有发送到该帐户,该帐户也会回复以重试。

无论是否满足该短语,该功能都会运行一次。但是,如果同一用户尝试再次发布某个短语(与该短语匹配或不匹配)怎么办?如何避免出现重复状态错误?我不确定这里最好的方法是什么,因为它超出了我的知识范围。以下是代码的简化版本,在if同一用户满足这两个条件后返回重复状态错误,然后再次尝试发推文:

var Twit          = require('twit');
var T             = new Twit(config);

// Start a stream for listening for @mentions
var stream = T.stream('statuses/filter', { track: ['@someusername'] });
stream.on('tweet', somePhrase);

function somePhrase(tweet) {

  var request = tweet.text;
  var trigger = /(?:[^"']|^)(\bsome phrase\b)(?!["'])/ig;
  var name    = tweet.user.screen_name;
  var nameID  = tweet.id_str;

  // check to see if the tweet does not meet the request trigger
  if (request != trigger) {

    var …
Run Code Online (Sandbox Code Playgroud)

javascript twitter node.js twitter-streaming-api

2
推荐指数
1
解决办法
8952
查看次数

如何使用 Twitter API 回复提及

我有一个可以正常运行的 Twitter 机器人。当某人回复我时,即 @myTwitterHandle 是推文中的第一件事时,它会补充他们。以下代码允许我回复他们:

\n\n
function tweetEvent(tweet) {\n\n  // Who is this in reply to?\n  var reply_to = tweet.in_reply_to_screen_name;\n  // Who sent the tweet?\n  var name = tweet.user.screen_name;\n  // What is the text?\n  var txt = tweet.text;\n\n  // Ok, if this was in reply to me\n  // Replace myTwitterHandle with your own twitter handle\n  console.log(reply_to, name, txt);\n  if (reply_to === \'myTwitterHandle\') {\n\n  \xc2\xa6 // Get rid of the @ mention\n  \xc2\xa6 txt = txt.replace(/@selftwitterhandle/g, \'\');\n\n  \xc2\xa6 // Start a …
Run Code Online (Sandbox Code Playgroud)

serverside-javascript node.js twitter-streaming-api

2
推荐指数
1
解决办法
4546
查看次数

1
推荐指数
1
解决办法
179
查看次数

Playframework 和 Twitter Streaming API

如何从 Twitter Streaming API - POST statuses/filter 读取响应数据?我已建立连接并收到 200 状态代码,但我不知道如何阅读推文。我只想在推文到来时打印它们。

ws.url(url)
.sign(OAuthCalculator(consumerKey, requestToken))
.withMethod("POST")
.stream()
.map { response =>
  if(response.headers.status == 200)
    println(response.body)
} 
Run Code Online (Sandbox Code Playgroud)

编辑:我找到了这个解决方案

ws.url(url)
.sign(OAuthCalculator(consumerKey, requestToken))
.withMethod("POST")
.stream()
.map { response => 
  if(response.headers.status == 200){
    response.body
      .scan("")((acc, curr) => if (acc.contains("\r\n")) curr.utf8String else acc + curr.utf8String)
      .filter(_.contains("\r\n"))
      .map(json => Try(parse(json).extract[Tweet]))
      .runForeach {
        case Success(tweet) =>
          println("-----")
          println(tweet.text)
        case Failure(e) =>
          println("-----")
          println(e.getStackTrace)
      }
  }
}
Run Code Online (Sandbox Code Playgroud)

twitter scala playframework twitter-streaming-api playframework-2.5

0
推荐指数
1
解决办法
738
查看次数