我試圖使用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