我正在使用 LinkMaker 获取有关我正在播放的歌曲的 iTunes 详细信息。为此,我发现 LinkMaker 能够一次返回 json 数据和 1 个结果。
我正在使用这个 url 来执行我的查询:
http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/itmsSearch?lang=1&output=json&country=%@&term=%@&media=%@&limit=1 "
以下是您需要提供的参数:
> country : store country term : could
> contains artist name, song name, album
> media : music
例如,如果您想了解“U2”的一首名为“One”的歌曲的详细信息,这里是正确的 URL:
http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/itmsSearch?lang=1&output=json&country=US&term=U2%20one&media=music&limit=1
然后你会收到这样的 json 数据:
{
"resultCount":1,
"results": [
{"wrapperType":"track", "mediaType":"song", "artistName":"U2", "itemParentName":"Achtung Baby", "itemParentCensoredName":"Achtung Baby", "itemCensoredName":"One", "itemName":"One", "artistLinkUrl":"http://itunes.apple.com/us/artist/u2/id78500?uo=4", "artworkUrl60":"http://a1.phobos.apple.com/us/r1000/009/Features/32/9a/60/dj.mfynlttx.60x60-50.jpg", "artworkUrl100":"http://a1.phobos.apple.com/us/r1000/009/Features/32/9a/60/dj.mfynlttx.100x100-75.jpg", "country":"USA", "currency":"USD", "discCount":1, "discNumber":1, "itemExplicitness":"notExplicit", "itemLinkUrl":"http://itunes.apple.com/us/album/one/id368713?i=368617&uo=4", "itemPrice":"1.29000", "itemParentExplicitness":"notExplicit", "itemParentLinkUrl":"http://itunes.apple.com/us/album/one/id368713?i=368617&uo=4", "itemParentPrice":"9.99000", "previewUrl":"http://a1.phobos.apple.com/us/r1000/019/Music/b6/8c/c5/mzm.epegonxg.aac.p.m4a", "primaryGenreName":"Rock", "trackCount":12, "trackNumber":3, "trackTime":276042}]
}
然后您需要解码这些 JSON 数据。
NSDictionary *jsonResultsParsed = [jsonResults JSONValue];
最后得到你想要的:
NSDictionary *songDetailsDict = [[jsonResultsParsed objectForKey:@"results"] objectAtIndex:0];
如果要确定用户所在的国家/地区,则需要使用其语言环境确定其国家/地区,这是我正在使用的代码:
- (NSString *)getUserCountry
{
NSLocale *locale = [NSLocale currentLocale];
return [locale objectForKey: NSLocaleCountryCode];
}
希望这可以帮助。
蒂埃里
编辑:最后有一个文档可用:
http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html