2016-04-27 44 views
-1

我想拉取所有比某個max_id更早的推文。但是,我無法弄清楚在我的請求中添加max_id的位置,以便推送比指定推文更早的推文。我想在不改變計數的情況下做到這一點。這裏是我到目前爲止的代碼:如何將max_id添加到我的twitter(tweepy)請求中? (Python 2.7)

import requests 
import time 
import json 
import urllib 
import urllib2 
import datetime 
import tweepy 

ct = "INSERT CONSUMER TOKEN" 
cs = "INSERT CONSUMER SECRET" 
at = "INSERT ACCESS TOKEN" 
acs = "INSERT CONSUMER SECRET" 
count = 1 

twitter = "transportgovuk" 
consumer_token = ct 
consumer_secret = cs 
access_token = at 
access_secret = acs 
auth = tweepy.OAuthHandler(consumer_token,consumer_secret) 
auth.set_access_token(access_token,access_secret) 

api = tweepy.API(auth) 

max_id = "724916468975046656" 

for status in tweepy.Cursor(api.user_timeline,twitter).items(count): 
    print status 

有不改變計數指定max_id後直接拉鳴叫的一種方式?

回答

0

它看起來像你只需要max_id添加到tweepy.Cursor for循環是這樣的:

import requests 
import time 
import json 
import urllib 
import urllib2 
import datetime 
import tweepy 

ct = "INSERT CONSUMER TOKEN" 
cs = "INSERT CONSUMER SECRET" 
at = "INSERT ACCESS TOKEN" 
acs = "INSERT CONSUMER SECRET" 
count = 1 

twitter = "transportgovuk" 
consumer_token = ct 
consumer_secret = cs 
access_token = at 
access_secret = acs 
auth = tweepy.OAuthHandler(consumer_token,consumer_secret) 
auth.set_access_token(access_token,access_secret) 

api = tweepy.API(auth) 

status_ids= "724916468975046656" 

for status in tweepy.Cursor(api.user_timeline,twitter,max_id=status_ids).items(count): 
    print status 

這應該拉鳴叫與STATUS_ID「724916468975046656.」如果您想要更多,請將您的計數更改爲高於1的數字。

相關問題