Itunes API请求

时间:2017-04-12 23:37:25

标签: python json api itunes

我正在尝试向itunes发出API请求以获取特定艺术家的歌曲以及使用这些歌曲的JSON格式的字典。我的下面的代码没有返回任何错误,但我不知道我哪里出错了。任何帮助都会很棒。另外,我在一些行旁边放了评论,以帮助进一步解释。

    import json
    import requests
    def get_from_itunes(artist,songs):
    base_url = "http://itunes.apple.com/search"
    params_dict = {"term":bon+iver, "entity": music}
    resp = requests.get(base_url, params=params_dict)
    structured_resp_text = resp.text
    python_obj_data_from_itunes = json.loads(structured_resp_text)
# the python object is a dictionary
    itunes_dict_keys = python_obj_data_from_itunes.keys() # These keys are lists
    for key in itunes_dict_keys:
        print key # it's unicode. I have no clue how to proceed from here.
# I should be getting a dictionary
# And then getting to the key Track Name

    file_obj = open("itunes_file.txt", "w") #wrote a file containing a JSON formatted string 
# and then pasted that into the JSON editor
    file_obj.write(python_obj_data_from_itunes + "\n")
    file_obj.close()

    return get_from_itunes()

0 个答案:

没有答案