Reputation: 4465
I am making a Python request using the request library to TikTok. I managed to dig up the URL for their user details (I don't know whether this is legal or not. If it isn't, please let me know). When I try to parse it into json, it raises an exception. Could someone helpme parse/fix this? Here is the code: Python Code:
r1 = requests.get("https://www.tiktok.com/node/share/user/@nike?isUniqueId=true&verifyFp=verify_kb51zknj_GH98fcme_eDuR_4XzM_ATwp_s8TRdCzr8fwi&_signature=KBbp4AAgEBCtR.e4r-y0ZSgWqPAAHbR").json()
print(r1)
Output:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Thanks
Upvotes: 2
Views: 6613
Reputation: 11
I wrote a wrapper in Python that allows you to fetch Users, Videos, Hashtags, Videos by music, etc. The project can be found here - TikTokAPI-Python
For your problem of fetching a user -
Install
pip install PyTikTokAPI
Get user
from TikTokAPI import TikTokAPI
api = TikTokAPI()
user_obj = api.getUserByName("fcbarcelona")
Upvotes: 1
Reputation: 229
you must provide user-agent header, ie
headers = {
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
}
r1 = requests.get("https://www.tiktok.com/node/share/user/@nike?isUniqueId=true&verifyFp=verify_kb51zknj_GH98fcme_eDuR_4XzM_ATwp_s8TRdCzr8fwi&_signature=KBbp4AAgEBCtR.e4r-y0ZSgWqPAAHbR", headers=headers).json()
print(r1)
sory I tried to post it as comment, but failed to format the code xD
Upvotes: 6