Twitter api is giving error - python

I am writing this program to get data from twitter of hashtags but it give me the error
import twitter
import json
import urllib
twitter_search = twitter.Twitter(domain="search.twitter.com")
for page in range(1,2):
k_results=twitter_search.search(q="jonson",rpp=100,page=page)
print json.dumps(k_results, sort_keys=True, indent=1)
errors are
Traceback (most recent call last):
File "<pyshell#6>", line 2, in <module>
k_results=twitter_search.search(q="Burma",rpp=100,page=page)
File "build\bdist.win32\egg\twitter\api.py", line 173, in __call__
return self._handle_response(req, uri, arg_data)
File "build\bdist.win32\egg\twitter\api.py", line 198, in _handle_response
raise TwitterHTTPError(e, uri, self.format, arg_data)
TwitterHTTPError: Twitter sent status 410 for URL: search.json using parameters: (q=Burma&rpp=100&page=1)
details: οΎ‹

You try to use API 1.0 endpoint, http://search.twitter.com/search.format. It returns status 410, gone:
When API v1 is finally retired, all authenticated and unauthenticated requests to API v1 will return a HTTP 410 Gone status. Older widgets will receive the same response. This status code signifies that all API v1-era resources are gone and not coming back.
Correct url for 1.1 search is https://api.twitter.com/1.1/search/tweets.json
I don't know whether twitter module you're using is updated to use API 1.1, and suggest to use one of modules that is.

Related

Error when trying to request data with Delta Exchange API ? I am new to python and API, so cannot find a way to resolve the error

I am new to python and wanted to try out how API works and ultimately build a basic trading bot. I have an account in Delta Exchange. I created and connected to API which all went well. But when I requested for details like get_product() or get_assets(), I am getting error. what am I doing wrong here?
https://github.com/delta-exchange/python-rest-client
This is a Github guide for using this API if it helps
I am hiding the api key and secret for safety reasons, i know this a basic question. But thank you for help me
from delta_rest_client import DeltaRestClient
import requests
delta_client = DeltaRestClient(
base_url='https://testnet-api.delta.exchange',
api_key='xxxxxxxxxxxxxxxxxxxxxx', #hiding for privacy
api_secret='xxxxxxxxxxxxxxxxxxxxxxx' #hiding for privacy
)
product = delta_client.get_product(27)
response = delta_client.get_assets()
Error:
PS C:\Users\fahee> & C:/Users/fahee/AppData/Local/Microsoft/WindowsApps/python3.10.exe "c:/Users/fahee/Desktop/Programming/Delta Exchange/testbot.py"
Traceback (most recent call last):
File "c:\Users\fahee\Desktop\Programming\Delta Exchange\testbot.py", line 10, in <module>
product = delta_client.get_product(27)
File "C:\Users\fahee\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\delta_rest_client\delta_rest_client.py", line 73, in get_product
response = self.request("GET", "/v2/products/%s" % (product_id), auth=auth)
File "C:\Users\fahee\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\delta_rest_client\delta_rest_client.py", line 64, in request
res.raise_for_status()
File "C:\Users\fahee\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\requests\models.py", line 960, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://testnet-api.delta.exchange/v2/products/27

Twitter API returned a 401 (Unauthorized), Could not authenticate you

I simply want to post a tweet from my Raspberry Pi and keep getting a 401 error.
-----------------------------------------This is my code-----------------------------------------
import sys
from twython import Twython
consumer_key='x'
consumer_secret='x'
access_token='x'
access_token_secret='x'
twitter = Twython(
consumer_key,
consumer_secret,
access_token,
access_token_secret
)
twitter.update_status(status='Test')
----------------------------------------Trace back------------------------------------------------
Traceback (most recent call last):
File "/home/pi/Desktop/Programs/tweetTest.py", line 29, in <module>
twitter.update_status(status='Test')
File "/usr/lib/python3/dist-packages/twython/endpoints.py", line 123, in update_status
return self.post('statuses/update', params=params)
File "/usr/lib/python3/dist-packages/twython/api.py", line 274, in post
return self.request(endpoint, 'POST', params=params, version=version)
File "/usr/lib/python3/dist-packages/twython/api.py", line 264, in request
api_call=url)
File "/usr/lib/python3/dist-packages/twython/api.py", line 199, in _request
retry_after=response.headers.get('X-Rate-Limit-Reset'))
twython.exceptions.TwythonAuthError: Twitter API returned a 401 (Unauthorized), Could not authenticate you
First of all, it appears you have misspelled 'consumer_secret' in your Twython instance: concumer_secret.
Secondly, if you have a desktop app (which I assume you have since this is tagged "raspberry-pi") it looks like you don't need to provide access tokens, just the 'APP_KEY' and 'APP_SECRET'. If you are using the oauth tokens, you might want to provide the code where you are receiving those in case that is the source of the problem.

Instagram Client Error

I am new to the Instagram API. I used the following code from the example on the github to get the most recent popular media.
from instagram.client import InstagramAPI
id= "OMITTED"
secret = "OMITTED"
api = InstagramAPI(client_id=id, client_secret=secret)
popular_media = api.media_popular(count=20)
for media in popular_media:
print media.images['standard_resolution'].url
I get the following error:
File "example.py", line 6, in <module>
popular_media = api.media_popular(count=20)
File "/usr/lib/python2.6/site-packages/instagram/bind.py", line 197, in _call
return method.execute()
File "/usr/lib/python2.6/site-packages/instagram/bind.py", line 189, in execute
content, next = self._do_api_request(url, method, body, headers)
File "/usr/lib/python2.6/site-packages/instagram/bind.py", line 131, in _do_api_request
raise InstagramClientError('Unable to parse response, not valid JSON.', status_code=response['status'])
instagram.bind.InstagramClientError: (404) Unable to parse response, not valid JSON.
I know it is a valid instagram object because when I print(api). I get the following:
<instagram.client.InstagramAPI object at 0x145c2b10>
This is taken directly from the example and I can't tell what I am doing wrong! Any help would be great!
If u signed up after Nov 17th, Instagram popular photo feed is deprecated in new API.
The library you are using is old, it will only work for popular API if you had signed up for before November 17th
https://www.instagram.com/developer/changelog/

Instagram API docs invalid JSON error

I keep getting this error when I tried the examples in the python-instagram documentation:
from instagram.client import InstagramAPI
access_token = "YOUR_ACCESS_TOKEN"
client_secret = "YOUR_CLIENT_SECRET"
api = InstagramAPI(access_token=access_token, client_secret=client_secret)
recent_media, next_ = api.user_recent_media(user_id="userid", count=10)
for media in recent_media:
print media.caption.text
Error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Users/bli1/Development/Django/CL/cherngloong/cherngloong/lib/python2.7/site-packages/instagram/bind.py", line 197, in _call
return method.execute()
File "/Users/bli1/Development/Django/CL/cherngloong/cherngloong/lib/python2.7/site-packages/instagram/bind.py", line 189, in execute
content, next = self._do_api_request(url, method, body, headers)
File "/Users/bli1/Development/Django/CL/cherngloong/cherngloong/lib/python2.7/site-packages/instagram/bind.py", line 131, in _do_api_request
raise InstagramClientError('Unable to parse response, not valid JSON.', status_code=response['status'])
InstagramClientError: (404) Unable to parse response, not valid JSON.
I'm not sure what is causing this error. I got my access_token and filled in all the parameters
I get the same error when I try other parts of the documentation:
api = InstagramAPI(client_id='YOUR_CLIENT_ID', client_secret='YOUR_CLIENT_SECRET')
popular_media = api.media_popular(count=20)
for media in popular_media:
print media.images['standard_resolution'].url
Ig made some major platform changes (introducing a Sandbox Mode) on Nov 17th that may be affecting your access.
I would check out this thread, from the repo you are using, plenty of SO links there as well.
A suggestion would be to bypass the python API and use curl with something like this for writing a comment (see if you can narrow down your error):
curl -F 'access_token=ACCESS-TOKEN' \
-F 'text=This+is+my+comment' \
https://api.instagram.com/v1/media/{media-id}/comments

Python oauth2 - getting access token

I want to integrate authenticated vimeo user's videos in my web application. I have this code https://gist.github.com/2944212
I made authorize call and now I got oauth_token, oauth_token_secret, oauth_verifier. I added all these things to the parameter and made request to the below url, but now I'm getting this error
>>> url = 'http://vimeo.com/oauth/access_token'
>>> req = oauth.Request(method='GET', url=url, parameters=params)
>>> req.sign_request(signature_method, consumer, token)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/oauth2/__init__.py", line 502, in sign_request
self['oauth_signature'] = signature_method.sign(self, consumer, token)
File "/usr/lib/python2.7/dist-packages/oauth2/__init__.py", line 838, in sign
key, raw = self.signing_base(request, consumer, token)
File "/usr/lib/python2.7/dist-packages/oauth2/__init__.py", line 832, in signing_base
key += escape(token.secret)
AttributeError: 'str' object has no attribute 'secret'
Using that how can I fetch access_token and make this method to work https://developer.vimeo.com/apis/advanced/methods/vimeo.videos.getUploaded
I'm new to oauth and I need your help.
Thanks!
UPDATE
Now I solved that error. The only thing I need is to get the access token and a script to make the request for this method https://developer.vimeo.com/apis/advanced/methods/vimeo.videos.getUploaded
If I understand correctly you now have the access token?
To make requests to the API endpoint follow the same procedure but use the access token (as the oauth_token parameter) and in the req.sign method. Direct your request towards the API URL aswell, of course :)
And you don't need the oauth_verifier once you have the access token.

Categories

Resources