我正在学习如何通过python-instagram包使用Instagram API。 我已经设置了客户端,拥有客户端ID和客户端密码。我已经使用get_access_token.py脚本在python-Instagram的得到一个访问令牌,但由于某些原因,我总是收到此错误:Python Instagram API - API请求失败
Traceback (most recent call last):
File "<ipython-input-38-6440f86cbefd>", line 1, in <module>
runfile('F:/PythonProjects/minefield/instagram test.py', wdir='F:/PythonProjects/minefield')
File "C:\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 580, in runfile
execfile(filename, namespace)
File "F:/PythonProjects/minefield/instagram test.py", line 13, in <module>
api.user_search(q='samsungmobile')
File "C:\Anaconda\lib\site-packages\instagram\bind.py", line 196, in _call
return method.execute()
File "C:\Anaconda\lib\site-packages\instagram\bind.py", line 182, in execute
include_secret=self.include_secret)
File "C:\Anaconda\lib\site-packages\instagram\oauth2.py", line 224, in prepare_request
url = self._full_url_with_params(path, params, include_secret)
File "C:\Anaconda\lib\site-packages\instagram\oauth2.py", line 148, in _full_url_with_params
self._full_query_with_params(params) +
File "C:\Anaconda\lib\site-packages\instagram\oauth2.py", line 144, in _full_url
self._signed_request(path, {}, include_signed_request, include_secret))
File "C:\Anaconda\lib\site-packages\instagram\oauth2.py", line 172, in _signed_request
return "&sig=%s" % self._generate_sig(path, params, self.api.client_secret)
File "C:\Anaconda\lib\site-packages\instagram\oauth2.py", line 127, in _generate_sig
return hmac.new(secret, sig, sha256).hexdigest()
File "C:\Anaconda\lib\hmac.py", line 136, in new
return HMAC(key, msg, digestmod)
File "C:\Anaconda\lib\hmac.py", line 71, in __init__
if len(key) > blocksize:
TypeError: object of type 'NoneType' has no len()
这里是我的代码:
from instagram.client import InstagramAPI
access_token = '1********4.0*****5.fb1c**********39***7365*********'
api = InstagramAPI(access_token=access_token)
api.user_search(q='samsungmobile')
脚本调用最后一行时失败api.user_search(q ='samsungmobile') 我不知道这个TypeError是如何引发的,但我怀疑它可能与访问令牌有关。
我确定我使用的是正确的。 get_access_token.py脚本返回长度为2的元组,第一个索引包含访问令牌作为字符串,第二个索引包含一个包含关于谁有权使用该应用的用户信息的字典。