I got this error message when trying trigger this line of code (https://github.com/Instagram/python-instagram)
recent_media, next_ = api.user_recent_media(user_id="userid", count=10)
Full source code
from instagram.client import InstagramAPI
import sys
# get access token
if len(sys.argv) > 1 and sys.argv[1] == 'local':
try:
from test_settings import *
InstagramAPI.host = test_host
InstagramAPI.base_path = test_base_path
InstagramAPI.access_token_field = "access_token"
InstagramAPI.authorize_url = test_authorize_url
InstagramAPI.access_token_url = test_access_token_url
InstagramAPI.protocol = test_protocol
except Exception:
pass
# Fix Python 2.x.
try:
import __builtin__
input = getattr(__builtin__, 'raw_input')
except (ImportError, AttributeError):
pass
client_id = input("Client ID: ").strip()
client_secret = input("Client Secret: ").strip()
redirect_uri = input("Redirect URI: ").strip()
raw_scope = input("Requested scope (separated by spaces, blank for just basic read): ").strip()
scope = raw_scope.split(' ')
# For basic, API seems to need to be set explicitly
if not scope or scope == [""]:
scope = ["basic"]
api = InstagramAPI(client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri)
redirect_uri = api.get_authorize_login_url(scope = scope)
print ("Visit this page and authorize access in your browser: "+ redirect_uri)
code = (str(input("Paste in code in query string after redirect: ").strip()))
access_token = api.exchange_code_for_access_token(code)
api = InstagramAPI(access_token=access_token[0], 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 message
Traceback (most recent call last):
File "python-instagram-stream.py", line 44, in <module>
recent_media, next_ = api.user_recent_media(user_id="userid", count=10)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/instagram/bind.py", line 197, in _call
return method.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/instagram/bind.py", line 189, in execute
content, next = self._do_api_request(url, method, body, headers)
File "/Library/Frameworks/Python.framework/Versions/2.7/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'])
instagram.bind.InstagramClientError: (400) Unable to parse response, not valid JSON.
I already tried this solution but still producing same error message
instagram.bind.InstagramClientError: Unable to parse response, not valid JSON
I changed it from
api = InstagramAPI(access_token=access_token, client_secret=client_secret)
to
api = InstagramAPI(access_token=access_token[0], client_secret=client_secret)
Most likely problem is in your call to api.user_recent_media, as in this line:
recent_media, next_ = api.user_recent_media(user_id="userid", count=10)
Specifically I would doubt that "userid" is what is expected here.
I would think that using the value obtained from the call to a new line:
user_id = api.user_search('username')[0].id
would be more likely to give you success, where username is replaced by the actual user in question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With