我开始使用AlchemyAPI密钥从 url 中提取 json/xml 数据。alchemy url api 密钥在与查询的 url 一起输入时效果很好,但我希望 url 部分来自用户端,所以首先我使用以下代码创建了一个表单:
<form method="post" class="SearchCSS" action="/NENSearch.php?go" id="categorizer">
<h1>Enter your Queries</h1>
<input type="text" name="Search" placeholder="Enter the article URL">
<input type="submit" value="Search">
</form>
然后使用 PHP 将用户提交的 url 传递到 alchemy api 的端点并将 json 数据存储到一个变量中,然后使用以下代码显示解析的数据(问题:代码实际上没有显示任何内容):
<?php
echo "this works here";
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
if(preg_match("%^((http?://)|(www\.))([a-z0-9-].?)+(:[0-9]+)?(/.*)?$%i", $_POST['Search'])){
$url=$_POST['Search'];}
echo $url;}
$response = file_get_contents("http://gateway-a.watsonplatform.net/calls/url/URLGetCombinedData?extract=page-image,entity,keyword,taxonomy&apikey=1f324507a9d516d9429e14f970ccc83de9df2&showSourceText=1&sentiment=1&outputMode=json"ations=1&url='.$url.'");
$response = json_decode($response);
echo $response;}
echo "<br/> this is not working";
?>
我使用的基本 alchemyAPI url 看起来像这样(最后添加了 drupal url): http://access.alchemyapi.com/calls/url/URLGetRankedTaxonomy?apikey=1f324507a9d51694a29e14f970ccc83de9df2&outputMode=jsonp&knowledgeGraph=1&extract=taxonomy&url=https://www. drupal.org/node/2148541
我刚开始使用 API,在将解析的 json 数据显示为 html 表单方面的任何帮助都会有很大帮助。提前致谢。:)