Twitter sent status 401 for URL -


i learning function of python aims retrieve trends twitter.

below following code wrote

import pickle  import os    if not os.path.exists('secret_twitter_credentials.pkl'):      twitter={}      twitter['consumer key'] = ''      twitter['consumer secret'] = ''      twitter['access token'] = ''      twitter['access token secret'] = ''      open('secret_twitter_credentials.pkl','wb') f:          pickle.dump(twitter, f)  else:      twitter=pickle.load(open('secret_twitter_credentials.pkl','rb'))        !pip install twitter    !pip install python-twitter    import twitter    auth = twitter.oauth.oauth(twitter['access token'],                             twitter['access token secret'],                             twitter['consumer key'],                             twitter['consumer secret'])    twitter_api = twitter.twitter(auth=auth)    # nothing see displaying twitter_api except it's  # defined variable    print(twitter_api)    world_woe_id = 1  us_woe_id = 23424977    local_woe_id=2487889    # prefix id underscore query string parameterization.  # without underscore, twitter package appends id value  # url special case keyword argument.    world_trends = twitter_api.trends.place(_id=world_woe_id)  us_trends = twitter_api.trends.place(_id=us_woe_id)  local_trends = twitter_api.trends.place(_id=local_woe_id)

i have filled consumer key, consumer secret, access token, , access token secret according alpha-numeric characters generated tweeter apps management. now, keep them hided. result shows error written follows:

---------------------------------------------------------------------------  httperror                                 traceback (most recent call last)  c:\users\prome\anaconda3\lib\site-packages\twitter\api.py in _handle_response(self, req, uri, arg_data, _timeout)      318             consumer_key of twitter account.  --> 319           consumer_secret:      320             consumer_secret twitter account.    c:\users\prome\anaconda3\lib\urllib\request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)      222         opener = _opener  --> 223     return opener.open(url, data, timeout)      224     c:\users\prome\anaconda3\lib\urllib\request.py in open(self, fullurl, data, timeout)      531             meth = getattr(processor, meth_name)  --> 532             response = meth(req, response)      533     c:\users\prome\anaconda3\lib\urllib\request.py in http_response(self, request, response)      641             response = self.parent.error(  --> 642                 'http', request, response, code, msg, hdrs)      643     c:\users\prome\anaconda3\lib\urllib\request.py in error(self, proto, *args)      569             args = (dict, 'default', 'http_error_default') + orig_args  --> 570             return self._call_chain(*args)      571     c:\users\prome\anaconda3\lib\urllib\request.py in _call_chain(self, chain, kind, meth_name, *args)      503             func = getattr(handler, meth_name)  --> 504             result = func(*args)      505             if result not none:    c:\users\prome\anaconda3\lib\urllib\request.py in http_error_default(self, req, fp, code, msg, hdrs)      649     def http_error_default(self, req, fp, code, msg, hdrs):  --> 650         raise httperror(req.full_url, code, msg, hdrs, fp)      651     httperror: http error 401: authorization required    during handling of above exception, exception occurred:    twitterhttperror                          traceback (most recent call last)  <ipython-input-85-fbc9b27282e9> in <module>()        5 # url special case keyword argument.        6   ----> 7 world_trends = twitter_api.trends.place(_id=world_woe_id)        8 us_trends = twitter_api.trends.place(_id=us_woe_id)        9 local_trends = twitter_api.trends.place(_id=local_woe_id)    c:\users\prome\anaconda3\lib\site-packages\twitter\api.py in __call__(self, **kwargs)      310                        consumer_secret,      311                        access_token_key=none,  --> 312                        access_token_secret=none,      313                        application_only_auth=false):      314         """set consumer_key , consumer_secret instance    c:\users\prome\anaconda3\lib\site-packages\twitter\api.py in _handle_response(self, req, uri, arg_data, _timeout)      343                                      access_token_key, access_token_secret)      344   --> 345         self._config = none      346       347     def gethelpconfiguration(self):    twitterhttperror: twitter sent status 401 url: 1.1/trends/place.json using parameters: (id=1&oauth_consumer_key=dhhqmxjsbhrnmobvhhotkf93p&oauth_nonce=8506939868455951796&oauth_signature_method=hmac-sha1&oauth_timestamp=1501000649&oauth_token=138680681-drmsjn3cnekystfpbf9ph7a6z2dim7cybjaberrq&oauth_version=1.0&oauth_signature=yr1kinkmquakmc7qxdbs7ry%2bosa%3d)  details: {'errors': [{'code': 89, 'message': 'invalid or expired token.'}]}

any idea part should modify?

thank you


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -