jeudi 31 mai 2018

vcr.py store call from twitter api

I want to use https://github.com/bear/python-twitter/ and check API requests https://github.com/kevin1024/vcrpy or https://github.com/agriffis/vcrpy-unittest.

From lines 30:

https://github.com/bear/python-twitter/blob/master/twitter/api.py#L30

30: import requests

and later on:

        res = requests.post(url='https://api.twitter.com/oauth2/token',
                            data={'grant_type': 'client_credentials'},
headers=post_headers)
        # ... etc ...

Yet when doing something like:

from vcr_unittest import VCRTestCase
import vcr
import twitter
from django.conf import settings


class TwitterRetrievalAndStorageTests(VCRTestCase):
    @vcr.use_cassette()
    def test_recorded_session(self):
        api = twitter.Api(
            consumer_key=settings.TWITTER_CONSUMER_KEY,
            consumer_secret=settings.TWITTER_CONSUMER_SECRET,
            access_token_key=settings.TWITTER_ACCESS_KEY,
            access_token_secret=settings.TWITTER_ACCESS_SECRET)

        statuses = api.GetUserTimeline(screen_name='nntaleb')
        for s in statuses:
            print(s)

Not a cassette file is being created. Is there a way to do this with python-twitter?

Aucun commentaire:

Enregistrer un commentaire