Currently I want to use CHACHA API but I don knoow to get call API via ASP.NET. When I search I found PHP code is possible to get chacha API. Also I don know to from PHP to ASP.NET could anybody help me to convert from PHP to ASP.NET code as below codes:
$chacha = new ChaChaAPI('your-key-here');
$trends = $capi->getTrends('What is Twitter');
$answer = $capi->ask("Who is Brandon Corbin?"); // Returns JSON object
Please remember to click “Mark as Answer” on the post that helps you and to unmark it if a marked post does not actually answer your question.
Thank you!
----------------------
"Microsoft Community Contributor Award 2011"
Hello, It is nice features but I don't want to do that because I need a class to send request and then get response from CHACHA API. When I got it I need to take the response for other purpose.
Sorry about my earlier post. My oversight. I mistook "ChaCha" for "CAPTCHA".
I will try to find a solution for your issue.
Please remember to click “Mark as Answer” on the post that helps you and to unmark it if a marked post does not actually answer your question.
Thank you!
----------------------
"Microsoft Community Contributor Award 2011"
lbuntha
Member
15 Points
21 Posts
Convert from PHP to ASP.NET
Nov 20, 2010 07:41 AM|LINK
Hello everybody,
Currently I want to use CHACHA API but I don knoow to get call API via ASP.NET. When I search I found PHP code is possible to get chacha API. Also I don know to from PHP to ASP.NET could anybody help me to convert from PHP to ASP.NET code as below codes:
$chacha = new ChaChaAPI('your-key-here');
$trends = $capi->getTrends('What is Twitter');
$answer = $capi->ask("Who is Brandon Corbin?"); // Returns JSON object
echo "<h2>Answer Response:</h2>";
echo json_encode($answer);
echo "<h2>Trends Response:</h2>";
echo json_encode($answer);
class getAPI {
var $apikey = '';
public function __construct($apikey) {
$this->apikey = $apikey;
}
public function ask($question) {
return $this->_call('http://query.chacha.com/answer/search.json?query='.urlencode($question));
}
public function getTrends($count=20) {
return $this->_call('http://query.chacha.com/trends/getTrends.json?source=RawQuery&count='.$count);
}
private function _call($url) {
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"apikey: ".$this->apikey."\r\n"
)
);
$context = stream_context_create($opts);
$request = file_get_contents($url, false, $context);
return json_decode($request);
}
}
Thank for your good support.
santa_1975
Star
8574 Points
1499 Posts
Re: Convert from PHP to ASP.NET
Nov 20, 2010 08:59 AM|LINK
Hi,
Here is a ready-made ASP.NET CAPTCHA control that you can give a try.
http://www.codeproject.com/KB/custom-controls/CaptchaControl.aspx
Hope this helps.
Thank you!
----------------------
"Microsoft Community Contributor Award 2011"
lbuntha
Member
15 Points
21 Posts
Re: Convert from PHP to ASP.NET
Nov 20, 2010 09:13 AM|LINK
Hello, It is nice features but I don't want to do that because I need a class to send request and then get response from CHACHA API. When I got it I need to take the response for other purpose.
Please check chacha's requirement
http://developer.chacha.com/docs
Quick ChaCha Answer API Request
Thanks for help
santa_1975
Star
8574 Points
1499 Posts
Re: Convert from PHP to ASP.NET
Nov 20, 2010 01:22 PM|LINK
Hi,
Sorry about my earlier post. My oversight. I mistook "ChaCha" for "CAPTCHA".
I will try to find a solution for your issue.
Thank you!
----------------------
"Microsoft Community Contributor Award 2011"
lbuntha
Member
15 Points
21 Posts
Re: Convert from PHP to ASP.NET
Nov 21, 2010 01:22 AM|LINK
Thanks for your support. I think if you help me convert code from PHP to ASP.NET it will be powerful for me to work on ChACHA API.
Best regards;
lbuntha
Member
15 Points
21 Posts
Re: Convert from PHP to ASP.NET
Nov 22, 2010 03:23 AM|LINK
Dear santa_1975;
Thanks for your support. Could you help me to translate with the below code to ASP.NET. Now I am stupid with this....
private function _call($url) {
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"apikey: ".$this->apikey."\r\n"
)
);
$context = stream_context_create($opts);
$request = file_get_contents($url, false, $context);
return json_decode($request);
}
Best regards;
lbuntha
Member
15 Points
21 Posts
Re: Convert from PHP to ASP.NET
Nov 23, 2010 02:26 AM|LINK
Hello,
Now I found a solution to call chacha api. here is the code i found by myself:
HttpWebRequest
webRequest.ContentType =
webRequest.Method =
webRequest.Headers.Add({
jsonResponse = sr.ReadToEnd();
}
webRequest = (HttpWebRequest)WebRequest.Create("http://query.chacha.com/answer/search.json?query="+query );"application/json; charset=utf-8";"GET";"apikey:apikey provided by chacha");HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse(); string jsonResponse = string.Empty; using (StreamReader sr = new StreamReader(response.GetResponseStream()))Best regards;