我试图使用Wordnik PHP API,并遇到一些麻烦。我试图使用getDefinitions方法,但它返回一个错误:Notice: Trying to get property of non-object in C:\xampp\htdocs\index.php on line 18
。Wordnik“尝试获取非对象的属性”错误尝试getDefinitions时
这里是下面的代码:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form method="post">
<input type="text" placeholder="First Word" name="word1">
<input type="submit" placeholder="Compare">
</form>
<?php
require('./wordnik/Swagger.php');
$APIKey = '342eac9900e703079b0050d5f7008eab962195189e75bfbcb';
$client = new APIClient($APIKey, 'http://api.wordnik.com/v4');
$word1 = $_POST['word1'];
$wordApi = new WordApi($client);
$word1 = $wordApi->getDefinitions($word1, null, null);
print $word1->text;
?>
</body>
</html>
你也可以看看:http://stackoverflow.com/a/12769983/2377164 – olibiaz