Я пытаюсь создать поисковое приложение, используя python. Я удалил свой ключ.
import requests
from requests_oauthlib import OAuth1
import json
from urllib.parse import urlparse
#Endpoints
url_rest = "https://api.twitter.com/1.1/search/tweets.json"
url_streaming = "https://stream.twitter.com/1.1/statuses/sample.json"
#Define parameters
params = {
app_key:'myPersonalKey',
app_secret:'myPersonalKey',
oauth_token:'myPersonalKey',
oauth_token_secret:'myPersonalKey'
}
auth = OAuth1(
auth_params['myPersonalKey'],
auth_params['myPersonalKey'],
auth_params['myPersonalKey'],
auth_params['myPersonalKey']
)
q = '@marchmadness'
params = {'q' : q, 'count' : 100, 'lang' : 'en'}
results = requests.get(url_rest,params=params, auth=auth)
for tweet in results.json()['statuses']:
print (tweet['text'])
stream_results = requests.get(url_streaming, stream=True,auth=auth)
for line in stream_results.iter_lines():
try:
decoded_line = line.decode('utf-8')
print(json.loads(decoded_line)['text'])
except:
pass
Вот ошибка, которую я получаю:
NameError Traceback (последний вызов последним)
в
10 # Определить параметры
11 параметров = {
---> 12 app_key: '',
13 app_secret: '',
14 oauth_token: '',
NameError: имя 'app_key' не определено
Это из книги "Python Social Media Analytics"