【娱乐时间】漫威API 回味复联11年

在这里插入图片描述
pictures from marvel website

用漫威API做个程序回味妇联
看完妇联后在漫威官网上找到了这个api,里面包含了漫威宇宙的所有人物、事件、宇宙等等,github上也有很多相关的资源和py包。有了这些就可以愉快的再创造自己的小宇宙了。

Marvel API

这个API为开发者们提供了丰富的漫威宇宙数据信息,甚至可以查询到七八十年前的各种故事、角色。
在这里插入图片描述

我们可以使用这个API制作人物关系图、事件发展和关联以及各种精彩的可视化或者小游戏。
首先需要到下面的页面注册,然后拿到你的apikey=xxxxx在这里插入图片描述

然后在这个页面将看到文档](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的开发者们已经开发了各种封装调用来方便大家接入漫威宇宙了:
在这里插入图片描述

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实现

在这里插入图片描述





看完妇联,写一个自己的app/小程序来总结漫威给我们带来的时光,也是一种最好的回忆和纪念了~~~~
在这里插入图片描述
pictures from marvel website

posted @ 2019-04-30 11:56  hitrjj  Views(147)  Comments(0Edit  收藏  举报