Home>

In a nutshell I don't know how to hit TwitterAPI.
Access token and access token secret are stored in DB, and it will be searched.
After that, I wrote the following code using them, but I get an error.

api = twitter.api (consumer_key = CONSUMER_KEY,
                  consumer_secret = CONSUMER_SECRET,
                  access_token_key = user.access_token,
                  access_token_secret = user.access_token_secret)
TypeError: 'module' object is not callable
class User (models.Model):
    id = models.BigIntegerField (primary_key = True)
    access_token = models.CharField (max_length = 255)
    access_token_secret = models.CharField (max_length = 255)
# A page that provides functions using access tokens
def app (request):
    access_token = request.session.get ("access_token", None)
    if not access_token:
        # Switch to sign-in if there is no access token in the session
        return redirect ("myapp.views.signin")
    user = User.objects.get (access_token = access_token)
    # Below, hit the API using the consumer key/secret and access token/secret

    return render (request, 'myapp/app.html')

How should I describe it?

  • Answer # 1

      

    TypeError:'module'object is not callable

    This error often occurs when running code forpython-twitterafter installing anotherTwitterlibrary aspip install twitterIt is an error.
    ◇ Reference information
    Want to RT on Twitter api, but bug in sample?

    There is noinformation on the library used in the question text, so first check that the installed library is correct with the following code.

    import twitter
    print (twitter .__ path__)
    print (dir (twitter))

    b.twitter.apitwitter.Api

    c. Regardless ofDjango, first check the operation of the script by operating theTwitter APIfrom thePythonscript. ,Djangocan be identified as a problem ofDjangoorTwitter APIoperation.