Instagram Client Error - python

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/

Related

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.

TwythonError: Twitter API returned a 404 for string 'usernames'

I am refering to this article.The article used twython to download user profile information with reference to UserID (int) and I am trying to use username(str).
The exact same code works when userID is given and when the same user's username is given this gives me an error.
what should I change in the program to read and process the usernames ? I have checked several question here and other forums the 404 is shown when the user is no longer available twitter user.
But to test that theory I did use same userid and username of which I can return the user profile fields but when the same user's username or screenname is used I am getting error.
Error:
Traceback (most recent call last):
File "user_prof_twython.py", line 25, in <module>
users = t.lookup_user(user_id = ids)
File "/usr/local/lib/python2.7/dist-packages/twython/endpoints.py", line 522, in lookup_user
return self.get('users/lookup', params=params)
File "/usr/local/lib/python2.7/dist-packages/twython/api.py", line 264, in get
return self.request(endpoint, params=params, version=version)
File "/usr/local/lib/python2.7/dist-packages/twython/api.py", line 258, in request
api_call=url)
File "/usr/local/lib/python2.7/dist-packages/twython/api.py", line 194, in _request
retry_after=response.headers.get('X-Rate-Limit-Reset'))
twython.exceptions.TwythonError: Twitter API returned a 404 (Not Found), No user matches for specified terms.
This works for me. Is this what you want?
Please note, screen_name can be a list. e.g.: ["aaaa","bbb","ccc","ddd"]
# Create a Twython instance with your application key and access token
twitter = Twython(APP_KEY, APP_SECRET, oauth_version=1)
output = twitter.lookup_user(screen_name="BarackObama")
for user in output:
print user["id_str"]
print user['created_at']
print user['followers_count']

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

How do I search for a user in Foursquare using the mLewisLogic python wrapper?

I'm having some trouble working with the Foursquare API. My end goal is to obtain a user's information (profile stats, twitter ids, facebooks ids, ...) from the Foursquare API. I would like to search for a user by either Twitter ID or name. My first attempt is using the foursquare recommended python wrapper called foursquare. Here is the documentation: https://github.com/mLewisLogic/foursquare
Here is my rather simple code:
import foursquare
client_id = xxx
client_secret = yyy
client = foursquare.Foursquare(client_id, client_secret)
print client.users.search(params={'twitter': 'nike'})
and here is my error:
Traceback (most recent call last):
File "D:\Users\nbush\workspace\Foursquare - API\main_foursq.py", line 12, in <module>
users = client.users.search(params={'twitter': 'nike'})
File "C:\Python27\lib\site-packages\foursquare\__init__.py", line 301, in search
return self.GET('search', params, multi=multi)
File "C:\Python27\lib\site-packages\foursquare\__init__.py", line 272, in GET
return self.requester.GET(self._expanded_path(path), *args, **kwargs)
File "C:\Python27\lib\site-packages\foursquare\__init__.py", line 200, in GET
result = _get(url, headers=headers, params=params)
File "C:\Python27\lib\site-packages\foursquare\__init__.py", line 787, in _get
return _process_response(response)
File "C:\Python27\lib\site-packages\foursquare\__init__.py", line 822, in _process_response
return _raise_error_from_response(data)
File "C:\Python27\lib\site-packages\foursquare\__init__.py", line 834, in
_raise_error_from_response
raise exc(meta.get('errorDetail'))
foursquare.NotAuthorized: A user is required to call this endpoint.
Any help would be great. Also if there is a better API or an easier way to do this with urllib2 or something then any suggestions would be appreciated. Alos, does anyone know if mLewisLogic is up to date with foursquare API v2? And is there a more complete documentation? Thanks in advance!
Add access_token
client = foursquare.Foursquare(client_id, client_secret, **access_token**)

Twitter api is giving error

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.

Categories

Resources