Because sometimes it is necessary to share some external information on the blog, in order to make the shared card contain some basic information and have real-time collection, I have gathered some APIs. When writing articles, you can insert the shortcode [share url] [/share]
to achieve automatic parsing. You only need to fill in the sharing URL without any additional information, which is very convenient.
Game Information#
Steam Game Information#
For sharing Steam games, the simplest way is to use the iframe
tag to call the small widget provided by the official:
However, since Steam is in a semi-blocked state, the loading speed of this thing is really not commendable, and in some places, the network cannot load it at all (for example, my home 😣). Similarly, the Steam game information API https://store.steampowered.com/api/appdetails
is also not recommended due to loading speed issues.
Xiaohei Box API#
Here, it is recommended to use the Xiaohei Box API https://api.xiaoheihe.cn/game/web/get_game_detail
.
The necessary parameters are the current timestamp _time
and the Steam game ID appid
. Just like this: https://api.xiaoheihe.cn/game/web/get_game_detail/?_time=1663404056&appid=289070
.
If the request includes the parameters os_type=web&version=999.0.2
, then an additional hkey
parameter must be included, otherwise, it will prompt that hkey cannot be empty. There is no latest algorithm for calculating hkey available online, and since the algorithm for hkey changes frequently, I do not intend to spend time researching this. Currently, it seems that a small number of games may not return price information without the hkey
parameter, so if used, you need to be prepared for fallback handling.
Steam API#
The necessary parameter for the Steam API is the game ID appids
, and it is recommended to include the region for querying the game cc=cn
, so that the returned price will be in Chinese Yuan (CNY); at the same time, including the l=schinese
parameter will replace the text such as tags and game descriptions with Chinese text (provided that the publisher has localized the game page in Chinese).
Finally, since the Steam API returns an extremely large amount of information, almost double that of the Xiaohei Box API, it exacerbates the already slow loading speed. In response to this situation, Steam provides a filters
parameter that allows users to specify and filter the required information. However, it should be noted that this parameter can only filter out object collections (i.e., data structures surrounded by curly braces {} or square brackets []). This means that once the filters parameter is used for filtering, all non-object collection data, such as the game name name, will be excluded. Currently, no solution has been found to overcome this limitation. Usage is just like this: https://store.steampowered.com/api/appdetails/?appids=814380&cc=cn&l=schinese
.
Note
By the way, the prices and discounts returned by the Xiaohei Box API are those of Xiaohei Box, not Steam's prices and discounts.
The parsing effect is as follows:
Game Corresponding Platform Links#
To obtain the store page link corresponding to the platform game, you need to directly use the platform's built-in API (usually the platform's search API).
Steam#
For the Steam platform, you can construct the game link by appending steam_appid
to the base URL https://store.steampowered.com/app/
.
For example, the link for "Overcooked! 2" is https://store.steampowered.com/app/728880
.
Switch#
The game search for the Switch platform can be achieved through the https://search.nintendo.jp/nintendo_soft/search.json
API, where the key parameter q
represents the game name and supports English or Japanese. If you directly use the Chinese name, such as q=集合啦!动物森友会
, you will not be able to obtain game information.
For example, the API URL for "Xenoblade 3" is: https://search.nintendo.jp/nintendo_soft/search.json?q=Xenoblade3
. By using the id
value returned by the API, you can construct the game's link in the Switch store, such as: https://store-jp.nintendo.com/list/software/70010000053335.html
.
Ubisoft#
The game search API for the Ubisoft platform is https://zh-cn.ubisoft.com/news2/search_name
, which requires the game_keyword
parameter and supports searching for Chinese game names.
For example, the API URL for searching "Skull and Bones" is: https://zh-cn.ubisoft.com/news2/search_name?game_keyword=碧海黑帆
.
By appending the returned gameabb
value to https://zh-cn.ubisoft.com
, you can obtain the game link, such as: https://zh-cn.ubisoft.com/skull_and_bones
.
Blizzard#
Warning
💩 Search Inaccuracy Warning
The search results on the Blizzard platform may be inaccurate.
The game search API for the Blizzard platform is https://tw.shop.battle.net/api/search
, which requires two parameters: q
(game name) and l
(language code, such as en-us
or zh-tw
).
For example, the API URL for searching "Warcraft III: Reforged" is: https://tw.shop.battle.net/api/search?q=Warcraft III: Reforged&l=en-us
. After obtaining the destination
from the returned data, append it to the base URL https://tw.shop.battle.net/zh-tw
to construct the game link, such as: https://tw.shop.battle.net/zh-tw/product/warcraft-iii-reforged
.
Other Platforms#
For platforms like Playstation, Xbox, iOS, etc., no direct APIs have been found, and web scraping is usually used to obtain game links.
As for Epic, due to encrypted parameters and anti-scraping strategies, and the Origin platform lacking a public API, these platforms will directly use the game links provided by the Xiaohei Box.
Bilibili Information#
Video#
Similar to sharing Steam game cards, Bilibili can also share video information through the iframe
tag:
The API call for Bilibili video information is relatively simple, requiring only a parameter bvid
or aid
that represents the video. For example: https://api.bilibili.com/x/web-interface/view?bvid=1NT411u7n9
.
The parsing effect is as follows:
Dynamic#
The API for Bilibili dynamic information is also simple, requiring a parameter id
that represents the dynamic content, as well as an optional timezone offset timezone_offset
(in minutes, default value is -480
). For example: https://api.bilibili.com/x/polymer/web-dynamic/v1/detail?id=706453546894098487
.
Note
The array of dynamic content rich_text_nodes
will be separated by emojis as array delimiters. For example, the sentence "This is a text post[Give Heart]More text" will be divided into three elements in the array: This is a text post, [Give Heart], More text. Therefore, it is necessary to traverse the array and concatenate the elements to obtain the complete dynamic content.
Danmaku#
The API for danmaku information requires a parameter oid
that represents the video, which is the video's cid
, and can be obtained through the video information API. For example, to get the danmaku for the video with cid
834814323: https://api.bilibili.com/x/v1/dm/list.so?oid=834814323
. The data format returned by the API is XML.
[!NOTE]
- The video's
cid
is not the same concept as the video's AV/BV number. For example, the video with BV number 1NT411u7n9 corresponds tocid
834814323.- The returned data is compressed with deflate and needs to be decompressed. In PHP, you can use the
gzinflate()
function for decompression.
Focus on the following data:
-
The
<maxlimit>
tag contains the maximum number of danmaku for the video. -
The
<state>
tag indicates whether danmaku is open for the video, with0
meaning danmaku can be sent normally, and1
meaning the danmaku sending function is closed. -
The
<d p="114.63900,1,25,16777215,1673445087,0,xxxxxxxx,yyyyyyyyyyyyyyyyyyy,10"> Pressure finally reached the second creation</d>
tag contains the specific information of each danmaku. For detailed information, refer to: bilibili-API-collect Attribute p. From this, we can conclude that the danmaku with the content Pressure finally reached the second creation appeared at 114.639 seconds in the video, is a normal danmaku scrolling from right to left, with a font size of standard, font color of white, sent at 21:51:27 on January 11, 2023 (timestamp 1673445087), the danmaku pool type is normal danmaku, the sender's mid hash is an 8-digit alphanumeric combination xxxxxxxx, and the danmaku dmid is a 19-digit pure number yyyyyyyyyyyyyyyyyyy. When the danmaku shielding level is greater than 10, this danmaku can be shielded.
Github Repository Information#
Similarly, the API for Github repository information is also very simple; you just need to use https://api.github.com/repos/
followed by {username}/{repository name}
. Like this: https://api.github.com/repos/SocialSisterYi/bilibili-API-collect
.
The parsing effect is as follows:
Blog Article/Page Information#
Since Typecho has been upgraded to the latest version 1.2, the original plugin for outputting article information no longer works, so I can only add some functions myself.
In Function.php
, add:
// Get article information
public static function getCustom($uid){
$type = is_numeric($uid) ? 'post' : 'page';
$cidType = $type === "post" ? 'cid' : 'slug';
$f = Typecho_Widget::widget('Widget_Archive@'.$uid,'pageSize=1&type='.$type, $cidType.'='.$uid);
$archive_info = ['title'=> $f->title ,'desc' => $f->description ,'category' => $f->category ,'time' => date('Y.m.d', $f->created)];
return $archive_info;
}
Then create an independent page template to call getCustom()
by obtaining the parameters from the URL.
/**
* Article Information
* @package custom
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
function filter($uid){
preg_match_all("/[a-zA-Z0-9]/",$uid,$a);
return join('',$a[0]);
}
if(!empty(filter($_SERVER["QUERY_STRING"]))){
foreach (explode('&', filter($_SERVER["QUERY_STRING"])) as $value) {
if (strpos($value,'uid')!== false) $uid = explode('=', $value)[1];
}
$returnJson=['state'=>1,'data'=> Func::getCustom($uid)];
echo json_encode($returnJson, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
}else{
$returnJson=['state'=>-2,'message'=>"No valid UID input"];
echo json_encode($returnJson, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
}
Finally, add an independent page in the backend, and select the Article Information template. There is only one corresponding article cid
or page slug
parameter uid
. The article call is as follows: https://vinking.top/getInfo.html?uid=67
, and the independent page call is as follows: https://vinking.top/getInfo.html?uid=about
.
The article parsing effect is as follows:
Currently, I have only used these few most commonly used APIs, and I will write more external parsing when needed 🙈.
Ordinary URL Parsing#
Recently, I wrote an API that can parse ordinary pages, but some URLs may fail to parse, so let's make do with it for now...
2022.12.3: After optimization, the compatibility with different websites has been greatly improved.
Title and Description Parsed Successfully#
URL Title Parsing Failed#
Taking the official website of "Genshin Impact" as an example, from the image below, it can be observed that the content of the title
tag on this page is dynamically generated through a js file named config.54af175465c7448a0fa377d065a2d6da.js
, which means that the original static HTML does not contain the <title>
tag before the page is fully loaded, so the page title cannot be directly obtained.
However, this page defines the keywords
metadata, so when the <title>
tag cannot be obtained, we will choose the first value in keywords
as the parsed title. The reason for this is that the first value in keywords
usually corresponds to the page title, and when there is no other obvious information representing the webpage title, this is a feasible alternative.
URL Description Parsing Failed#
URL Does Not Exist#
URL Access Timeout Within the Country#
When the URL access times out within the country, it automatically uses a proxy to try again. If it times out again, it will downgrade to "URL does not exist" handling.
This article is synchronized and updated to xLog by Mix Space. The original link is https://www.vinking.top/posts/codes/game-and-social-media-sharing