开发者

wordnik-php api not connecting

开发者 https://www.devze.com 2023-04-02 08:02 出处:网络
I am learning php and I have learned only the basics. I am trying to connect to wordnik using their php apis (Wordnik.php), I created the following:

I am learning php and I have learned only the basics. I am trying to connect to wordnik using their php apis (Wordnik.php), I created the following:

开发者_开发问答<?php
require_once("Wordnik.php");
$api_key="MY_API_KEY";
$wordnik=Wordnik::instance($api_key);
var_dump($wordnik);
$definitions = $wordnik->getDefinitions('cat');
var_dump($definitions);
?>

The first var_dump is giving object(Wordnik)#1 (1) but there is no output for the later one. Can you please help me to solve this problem? Thank you


I think the issue might be that where it says "MY_API_KEY", you need to replace that with an actual API key that you get by registering with Wordnik. It's easy to get one, you just need to:

1) Sign up for a Wordnik account: http://www.wordnik.com/signup

2) Request an API key: http://developer.wordnik.com/

You should get the API key in your email within a few minutes.

Replace the "MY_API_KEY" part of your script with your actual API key, e.g.:

$api_key="d6g3f2fds6732r7sdf6d7ds6sd5gd67cvb5vc6237dfs";

That's not a real API key, but the one you get will look something like that, a string of letters and numbers.

Then your script ought to work for you. If not, please let me know. And if you need to write back for more help, don't share your actual API with us, that's for your eyes only.

Thanks for checking out the API, hope we can help you get it going.


Thanks @mrjf I finally got the solution

  1. I signed up for the Wordnik api and I had put the correct key. I had created a class where all the dictionary stuffs are handled. I removed that class and put it in single file which was accessible to user. I am not sure if its a right process but it works for the time being. Can anybody please tell how to make a class in php and call it from another php files something like #include "myFile.h" in C (I know require_once but it isn't working here, even a tutorial link would be great)?

  2. With wordnik api you also have to install cURL because internally wornik-php.api has many curl calls.

Some of the solutions here might be trivial to more experienced developers but if anybody like me is newbie to php and wordnik apis these ideas might help them.

0

精彩评论

暂无评论...
验证码 换一张
取 消