Search code examples
phpapiwordnik

Fatal error: Call to undefined method with Wordnik API


Not sure if this is an Wordnik API issue or just a php error on my part. Here is my current code:

require('./wordnik/Swagger.php');
require('./wordnik/WordsApi.php');

$myAPIKey = '00144cdc1140c4192780f08c3f608399234240dcb560d3e4b';
$client = new APIClient($myAPIKey, 'http://api.wordnik.com/v4');

$wordApi = new WordApi($client);
$input = new WordObject();
$input->includePartOfSpeech='noun';
$input->excludePartOfSpeech='affix,article,connjunction,preposition,abbreviation,suffix';
$input->hasDictionaryDef='true';
$input->minCorpusCount='10000';
$input->maxCorpusCount='null';
$input->minDictionaryCount='20';
$input->maxDictionaryCount=null;
$input->minLength='4';
$input->maxLength='20';

$random_word = $wordApi->getRandomWord($input); //THIS IS THE ERROR LINE
print $random_word->text;

and here is the error I get: Fatal error: Call to undefined method WordApi::getRandomWord()

Any help is greatly appreciated. The error is happening on that line towards the bottom, just not sure why. Thank you.


Solution

  • getRandomWord() is defined in WordsApi (plural words).

    • You have: WordApi
    • You need: WordsApi