![](/img/trans.png)
[英]How to get instagram user ID/access tocken from iphone app
[英]iPhone App: how to get app icon from app id?
我正在尋找一種從應用程序 ID 獲取應用程序圖標的方法。 你知道怎么做嗎? 請分享方法。 謝謝。
例如 Instagram,我要查找的 id 是:id389801252
https://itunes.apple.com/jp/app/instagram/id389801252?mt=8
我想得到這個圖像:
(我在谷歌搜索 2 分鍾后撰寫了這個答案......這只是正確關鍵字的問題!)
這可以使用 iTunes Store 的未記錄文檔API 來實現。 它在未來可能會改變,但它似乎在不久的過去沒有改變,所以你在這里......
NSString *idString = @"id389801252";
NSString *numericIDStr = [idString substringFromIndex:2]; // @"389801252"
NSString *urlStr = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@", numericIDStr];
NSURL *url = [NSURL URLWithString:urlStr];
NSData *json = [NSData dataWithContentsOfURL:url];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:json options:0 error:NULL];
NSArray *results = [dict objectForKey:@"results"];
NSDictionary *result = [results objectAtIndex:0];
NSString *imageUrlStr = [result objectForKey:@"artworkUrl100"]; // or 512, or 60
NSURL *artworkURL = [NSURL URLWithString:imageUrlStr];
NSData *imageData = [NSData dataWithContentsOfURL:artworkURL];
UIImage *artworkImage = [UIImage imageWithData:imageData];
請注意,這使用NSURL
API 執行兩個同步往返,因此您最好將其包裝在 backgorund 線程中以獲得最大的用戶體驗。 訂閱該程序的ID字符串( idString
並且在最后在上面的代碼), artworkImage
將包含所需的圖像一個UIImage。
僅供參考,您也可以使用應用程序的捆綁包 ID:
不確定這是否完全相關,但 Apple 提供了一個iTunes Link Maker工具。 如果您使用此工具查找您的應用程序,您還會看到它顯示應用程序圖標部分的位置。 單擊embed
並從那里獲取 img 鏈接。 需要注意的一件事,我最終使用了 url 來找到我需要的正確大小和格式(例如,您可以獲得 jpg 渲染而不是 png 或選擇任意大小,如 128x128)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.