webhose / webhoseio-php
Webz.io PHP SDK
dev-master
2022-04-17 14:46 UTC
Requires
- php: ^5.4|^7.0
- ext-curl: *
- ext-libxml: *
This package is not auto-updated.
Last update: 2024-09-18 20:38:47 UTC
README
从您的PHP代码中访问 Webz.io API的简单方法
// API Key from: https://webz.io/dashboard Webz::config("API_KEY"); //Perform a "filterWebContent" query using "United States" as our keywords. $params = array("q"=>"United States", "size"=>"3"); $result = Webz::query("filterWebContent", $params); //Fetch the next results using the same terms. $result = Webz::get_next();
API密钥
要使用webz.io API,您需要一个API密钥。
要获取一个,请在此注册: https://webz.io/auth/signup
您的密钥将在此处可用: https://webz.io/dashboard
使用方法
要开始,您需要导入类并用您的API密钥进行配置
require_once('webz.php'); // API Key from: https://webz.io/dashboard Webz::config("API_KEY");
API端点
查询()函数接受的第一个参数是API端点字符串。可用的端点
- filterWebContent - 访问news/blogs/forums/reviews API
- productFilter - 访问有关电子商务产品/服务的资料
- darkFilter - 访问暗网(即将推出)
现在您可以发出请求并检查结果
//Helper method to print result: function print_filterwebdata_titles($api_response) { if($api_response == null) { echo "<p>Response is null, no action taken.</p>"; return; } if(isset($api_response->posts)) foreach($api_response->posts as $post) { echo "<p>" . $post->title . "</p>"; } } //Perform a "filterWebContent" query using "United States" as our keywords. $params = array("q"=>"United States", "size"=>"3"); $result = Webz::query("filterWebContent", $params); print_filterwebdata_titles($result);
您可以像遍历任何PHP数组一样遍历结构
//Print more detailed information about the article: $params = array("q"=>"United States", "size"=>"1"); $result = Webz::query("filterWebContent", $params); foreach($result->posts as $post) { echo "<p>Site: <b>" . $post->thread->site . "</b></p>"; echo "<p>Categories:</p>"; echo "<ul>"; foreach($post->thread->site_categories as $category) { echo "<li>" . $category . "</li>"; } echo "</ul>"; }
根据使用的端点,生成的JSON数组可能包含"posts"、"products"等。您可以在浏览器中查看JSON以更清楚地了解返回数据。为了在浏览器中查看数据,我们可以启用调试标志以显示传递给cURL的URL
//If true, echoes the parameterised Webz API URL before executing request. Webz::enable_debug(true);
完整文档
-
Webz::config(api_key)
- api_key - 您的API密钥
-
Webz::query(end_point_str, params)
- end_point_str
- filterWebContent - 访问news/blogs/forums/reviews API
- productFilter - 访问有关电子商务产品/服务的资料
- darkFilter - 访问暗网(即将推出)
- params: 键值字典。 了解有关可用参数的更多信息。
- end_point_str
-
Webz::get_next()
- 使用相同的参数获取下一页的结果。 -
Webz::enable_debug(debug_enabled)
- debug_enabled - 布尔值,如果为true,则在执行请求之前输出参数化的Webz API URL。
轮询
可以使用相同的参数继续搜索以获取更多结果
//Perform a "productFilter" query using "United Kingdom" as our keywords. $params = array("q"=>"United Kingdom", "size"=>"1"); $result = Webz::query("productFilter", $params); print_productsearch_titles($result); //Fetch the next results using the same terms. $result = Webz::get_next(); print_productsearch_titles($result); $result = Webz::get_next(); print_productsearch_titles($result); //... //When $result is null, there are no more results available.
许可证
此存储库中的代码采用MIT许可证发布