天天看點

【娛樂時間】漫威API 回味複聯11年

【娛樂時間】漫威API 回味複聯11年

pictures from marvel website

用漫威API做個程式回味婦聯

看完婦聯後在漫威官網上找到了這個api,裡面包含了漫威宇宙的所有人物、事件、宇宙等等,github上也有很多相關的資源和py包。有了這些就可以愉快的再創造自己的小宇宙了。

Marvel API

這個API為開發者們提供了豐富的漫威宇宙資料資訊,甚至可以查詢到七八十年前的各種故事、角色。

【娛樂時間】漫威API 回味複聯11年

我們可以使用這個API制作人物關系圖、事件發展和關聯以及各種精彩的可視化或者小遊戲。

首先需要到下面的頁面注冊,然後拿到你的

apikey=xxxxx

【娛樂時間】漫威API 回味複聯11年

然後在這個頁面将看到文檔](https://developer.marvel.com/docs),其中詳細的說明了六大類api的調用方法:包括了宇宙、宇宙創造者、系列、角色、時間、故事等。都可以使用GET方法調用。

url:http://gateway.marvel.com/v1/public/some_api

例如對于每個角色的請求傳回的資料是這樣的:

//可以從裡面解析出各種資訊
CharacterDataWrapper {    //資料包裝
code (int, optional): The HTTP status code of the returned result.,
status (string, optional): A string description of the call status.,
copyright (string, optional): The copyright notice for the returned result.,
attributionText (string, optional): The attribution notice for this result. Please display either this notice or the contents of the attributionHTML field on all screens which contain data from the Marvel Comics API.,
attributionHTML (string, optional): An HTML representation of the attribution notice for this result. Please display either this notice or the contents of the attributionText field on all screens which contain data from the Marvel Comics API.,
data (CharacterDataContainer, optional): The results returned by the call.,
etag (string, optional): A digest value of the content returned by the call.
}
CharacterDataContainer {    //資料容器
offset (int, optional): The requested offset (number of skipped results) of the call.,
limit (int, optional): The requested result limit.,
total (int, optional): The total number of resources available given the current filter set.,
count (int, optional): The total number of results returned by this call.,
results (Array[Character], optional): The list of characters returned by the call.
}
Character {        //角色
id (int, optional): The unique ID of the character resource.,
name (string, optional): The name of the character.,
description (string, optional): A short bio or description of the character.,
modified (Date, optional): The date the resource was most recently modified.,
resourceURI (string, optional): The canonical URL identifier for this resource.,
urls (Array[Url], optional): A set of public web site URLs for the resource.,
thumbnail (Image, optional): The representative image for this character.,
comics (ComicList, optional): A resource list containing comics which feature this character.,
stories (StoryList, optional): A resource list of stories in which this character appears.,
events (EventList, optional): A resource list of events in which this character appears.,
series (SeriesList, optional): A resource list of series in which this character appears.
}
Url {   //對應連結
type (string, optional): A text identifier for the URL.,
url (string, optional): A full URL (including scheme, domain, and path).
}
Image {   //圖像及連結
path (string, optional): The directory path of to the image.,
extension (string, optional): The file extension for the image.
}
ComicList {   //宇宙
available (int, optional): The number of total available issues in this list. Will always be greater than or equal to the "returned" value.,
returned (int, optional): The number of issues returned in this collection (up to 20).,
collectionURI (string, optional): The path to the full list of issues in this collection.,
items (Array[ComicSummary], optional): The list of returned issues in this collection.
}
ComicSummary {
resourceURI (string, optional): The path to the individual comic resource.,
name (string, optional): The canonical name of the comic.
}
StoryList {   //故事
available (int, optional): The number of total available stories in this list. Will always be greater than or equal to the "returned" value.,
returned (int, optional): The number of stories returned in this collection (up to 20).,
collectionURI (string, optional): The path to the full list of stories in this collection.,
items (Array[StorySummary], optional): The list of returned stories in this collection.
}
StorySummary {
resourceURI (string, optional): The path to the individual story resource.,
name (string, optional): The canonical name of the story.,
type (string, optional): The type of the story (interior or cover).
}
EventList {    //事件
available (int, optional): The number of total available events in this list. Will always be greater than or equal to the "returned" value.,
returned (int, optional): The number of events returned in this collection (up to 20).,
collectionURI (string, optional): The path to the full list of events in this collection.,
items (Array[EventSummary], optional): The list of returned events in this collection.
}
EventSummary {
resourceURI (string, optional): The path to the individual event resource.,
name (string, optional): The name of the event.
}
SeriesList {  //系列
available (int, optional): The number of total available series in this list. Will always be greater than or equal to the "returned" value.,
returned (int, optional): The number of series returned in this collection (up to 20).,
collectionURI (string, optional): The path to the full list of series in this collection.,
items (Array[SeriesSummary], optional): The list of returned series in this collection.
}
SeriesSummary {
resourceURI (string, optional): The path to the individual series resource.,
name (string, optional): The canonical name of the series.
}
           

高層封裝

api手冊很長,感覺用起來有點複雜。Github的開發者們已經開發了各種封裝調用來友善大家接入漫威宇宙了:

【娛樂時間】漫威API 回味複聯11年
python方面的有:

1.pyMarvel

pip install PyMarvel

即可安裝

還有詳細文檔:http://pymarvel.readthedocs.org/

2.Marvel-API python

同樣是pip 安裝

pip install marvel

然後愉快的使用了:

from marvel import Marvel
m = Marvel(PUBLIC_KEY, PRIVATE_KEY)


#六類方法調用
characters = m.characters
comics = m.comics
creators = m.creators
events = m.events
series = m.series
stories = m.stories
           
js方面

marvel-api js

js愉快調用

var api = require('marvel-api');

var marvel = api.createClient({
  publicKey: 'my-public-key'
, privateKey: 'my-private-key'
});
           

一個用于顯示圖檔和簡介的js-React實作

【娛樂時間】漫威API 回味複聯11年

看完婦聯,寫一個自己的app/小程式來總結漫威給我們帶來的時光,也是一種最好的回憶和紀念了~~~~

【娛樂時間】漫威API 回味複聯11年

pictures from marvel website