2016-07-06 10 views
0

twitterからツイートを取得し、その結果をJSONに変換しようとしているMongoDBデータベースに保存します。
は、これは私のコードTweepy検索の結果をJSONフォームに変換する方法

import tweepy 
import json 
import pymongo 
from pymongo import MongoClient 
client=MongoClient() 
db=client.scholarship 

APP_KEY = app key here 
APP_SECRET = app secret here 
OAUTH_TOKEN = access-token here 
OAUTH_TOKEN_SECRET = token secret here 

auth=tweepy.OAuthHandler(APP_KEY,APP_SECRET) 
auth.set_access_token(OAUTH_TOKEN,OAUTH_TOKEN_SECRET) 

api=tweepy.API(auth) 

for tweet in tweepy.Cursor(api.search,q="scholarship",count=100,result_type="recent",include_entities=True,lang="en").items(): 
    tweet=json.dumps(tweet) 
    try: 
     db.daily.insert(tweet) 
    except Exception as e: 
     print "there is a problem ",e 
    else: 
     print "inserted" 

私はエラー
レイズはTypeError取得しています(のrepr(O)を+ "シリアライズJSONではありません")

serachの戻り値の型であることの理由は、のですフォーム
(貢献者=なし、切り捨て= Falseを、テキスト= u'RT @AnwenAb:@OralRobertsU 2016は、MedProのRx社\ ufffdEducationがパワー\ ufffd奨学金申請期限2016' 年6月1日、is_quote_status = Falseです)

は、提案が必要のここで行うことができます。
ありがとうございます!

答えて

2

これは です。カーソルがあなたにJSONを返さないためです。 tweepy.models.Statusモデルのインスタンスを返します。明らかにJSONとして解析することはできません。あなたは

tweet._json 
を使用することができるモデルから解析されたJSONを取得するために

関連する問題