×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    11

    Using Longman Dictionary API

    Hi i am trying to access Longman Dictionar API for s40 web app but getting error
    Failed to load resource: Proxy requires authentication in entry.json
    while the same coding is running well in IE,Firefox browser.

    Please help me.

  2. #2
    Registered User
    Join Date
    Jun 2008
    Location
    Port Elizabeth, South Africa
    Posts
    37

    Re: Using Longman Dictionary API

    Hi,

    I had a quick look at the Longman API, but without an API key I cannot be sure I got it working. I get the "Unauthorised" response from the service. I don't get any "Proxy requires authentication" error though.

    Update: I found an API key amongst source code on GitHub and this code does return the results I expect. Remember to sanitise your code before making it public folks!

    My code:

    Code:
    function callLongman(searchfor) {
    	var json;
            var responseObject;
            var apikey = ""; // Still waiting for one, I guess the process for getting one is manual
    	var xmlhttp;
    	xmlhttp = new XMLHttpRequest();
    	xmlhttp.open("GET", "https://api.pearson.com/longman/dictionary/0.1/entry.json?apikey=" + apikey + "&q=" + searchfor, false);
    	xmlhttp.send();
    
    	if (xmlhttp.status == 200) {
    		json = xmlhttp.responseText;
                     // Can now parse into an object. Not the safest way. Only use if you really trust the source.
                    responseObject = eval('(' + json + ')');
    		document.getElementById('info').innerHTML = json; 
    	} else {
    		document.getElementById('info').innerHTML = 'ERROR: ' + xmlhttp.statusText;
    	}
    }
    The particular error you are having (Failed to load resource: Proxy requires authentication in entry.json) is very likely caused by how you are loading, or trying to load, the various Javascript resources you are using. But without seeing your code I won't be able to say for sure.

    When I create a Web App, I try to not use helper Javascript libraries like JQuery as they are primarily there to help you overcome multiple browser support. A Web App runs on a well defined platform that you can easily code for without worrying about differences with other platforms.

    Side note on the xmlhttp call: I tend to use synchronous xmlhttp calls rather than the asynchronous alternative that most people favor. But I figure that the Nokia Proxy server will return when it is done no matter which type is used.

    I hope this helps.

    Stephen
    Last edited by sperelson; 2012-04-04 at 12:58.

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    11

    Re: Using Longman Dictionary API

    Hi Thnx for your reply here is my code

    var apiKey = '58023b8cfa0087e...............f';
    var baseUrl = 'https://api.pearson.com/longman/dictionary/0.1';
    var dataFmt = '.json';
    var searchUrl = baseUrl + '/entry' + dataFmt;
    //var searchUrl = baseUrl + '/entry' + dataFmt +'?'+apiKey;
    var debugLog;

    function init(){
    $("#results").hide();
    $('#search').click(function(event){
    event.preventDefault();
    doSearch($('#searchText').val());
    });
    debugLog = $('#log');
    }

    function doSearch(searchFor){
    debugLog.append('Looking up ' + searchFor + ' using ' + searchUrl + '<br/>');
    var data = 'apikey=' + apiKey + '&q=' + searchFor;
    $.ajax({
    type: 'POST',
    url: searchUrl,
    data: data,
    dataType: 'jsonp',
    jsonp: 'jsonp',
    success: function(data){
    handleResponse(data);
    },
    error: function(req, err, text ) {
    debugLog.append('Error: ' + status + '(' + text +')<br/>');
    }
    });
    $("#results").hide();
    }

    function handleResponse(data){
    debugLog.append('Response received <br/>');
    var results = data.Entries.Entry;
    var html = entry(results);
    $('#resultList').html(html);
    $('li>a').click(function(){
    $(this).parent().find("div").toggle();
    });
    $('#resultList > li > div').hide();
    $('#resultList > li:first > div').show();
    $("#results").show();
    debugLog.append('Response processed <br/>');
    }

    function entry(from){
    var html = '';
    if ($.isArray(from)){
    for (var idx in from){
    html += entry(from[idx]);
    }
    } else {
    debugLog.append("Processing Entry: " + from.Head.HWD['#text'] + '<br/>');
    html += '<li><a>';
    html += from.Head.HWD['#text'];
    html += '</a><div>';
    if ($(from).hasAttr('multimedia')) {
    html += multimedia(from.multimedia);
    }
    html += '<ol id="sense">';
    html += sense(from.Sense);
    html += '</ol>';
    html += '</div></li>\n';
    debugLog.append("<br/>Processed Entry: " + from.Head.HWD['#text'] + '<br/>');
    }
    return html;
    }


    function multimedia(from){
    debugLog.append('multimedia ');
    var html='';
    if ($.isArray(from)) {
    for (var idx in from){
    html += multimedia(from[idx]);
    }
    } else {
    var mm_href = from['@href'];
    var mm_type = from['@type'];
    if (mm_type =='EXA_PRON'){
    mm_type ='';
    }
    switch (mm_type){
    case 'EX_PRON':
    mm_type = '';
    break;
    case 'US_PRON':
    mm_type = 'American pronunciation';
    break;

    case 'SOUND_EFFECTS':
    mm_type = 'Sound effect';
    break;
    }
    if (mm_href.match(/\.mp3$/)) {
    html = mm_type + ' <audio controls="controls"> <source src="' + baseUrl + mm_href + '?apikey=' + apiKey +'" type="audio/mpeg"/> </audio>';
    } else if (mm_type == 'DVD_PICTURES') {
    html = '<img src="' + baseUrl + mm_href + '?apikey=' + apiKey +'"> </img>';
    }
    html += '<br/>';
    }
    return html;
    }


    function sense(from){
    debugLog.append('sense ');
    var html='';
    if ($.isArray(from)) {
    for (var idx in from){
    html += sense(from[idx]);
    }
    } else if ($(from).hasAttr('Subsense')) {
    html += sense(from.Subsense);
    } else {
    html += '<li>' + text(from.DEF) + '<br/>';
    if ($(from).hasAttr('EXAMPLE')){
    html += example(from.EXAMPLE);
    } else if ($(from).hasAttr('LEXUNIT')){
    html += example(from.LEXUNIT);
    }
    html += '</li>';
    }
    return html;
    }


    function example(from){
    debugLog.append('example ');
    var html ='';
    if ($.isArray(from)){
    for (var idx in from){
    html+= example(from[idx]);
    }
    } else {
    html += '<q>' + text(from) + '</q>';
    if ($(from).hasAttr('multimedia')){
    html += multimedia(from.multimedia);
    }
    }
    return html;
    }


    function text(from){
    debugLog.append('text ');
    var result = '';
    var text = from['#text'];
    var nonDv;
    var hasNonDv = $(from).hasAttr('NonDV');
    if ($.isArray(text)){
    for (var idx in text) {
    result += text[idx];
    if (hasNonDv){
    nonDv = from.NonDV[idx];
    if (nonDv != undefined){
    result += nonDv.REFHWD['#text'];
    }
    }
    }
    } else {
    result += text;
    if ($(from).hasAttr('NonDV')){
    result += from.NonDV.REFHWD['#text'];
    } else if ($(from).hasAttr('COLLOINEXA')){
    result += from.COLLOINEXA['#text'];
    }
    }
    return result;
    }

    I am using Jquery.js and hasAtrr.js with this one.

  4. #4
    Registered User
    Join Date
    Jun 2008
    Location
    Port Elizabeth, South Africa
    Posts
    37

    Re: Using Longman Dictionary API

    Hi,

    I spent some time trying to get your code to work. I couldn't get the hasAttr.js file and I decided to use the latest jquery.js rather.

    Some points:
    • The multimedia routines caused issues in the simulator, but worked fine on the phone (the Nokia Proxy stripped them out or down)
    • The jquery Ajax routine would not work in Cloud Preview nor on an actual device with Nokia Browser v1.5.0.34.15


    I used my ajax routine instead of the jquery one and it worked in Cloud Preview.

    So try replacing your doSearch routine with this one:

    Code:
    function doSearch(searchFor) {
    	debugLog.append('Looking up ' + searchFor + ' using ' + searchUrl + '<br/>');
    	var json;
    	var xmlhttp;
    	xmlhttp = new XMLHttpRequest();
    	xmlhttp.open("GET", searchUrl + '?apikey=' + apiKey + '&q=' + searchFor, false);
    	xmlhttp.send();
    
    	if (xmlhttp.status == 200) {
    		json = xmlhttp.responseText;
    		var data = eval('(' + json + ')');
    		handleResponse(data);
    	} else {
    		debugLog.append('Error: ' + xmlhttp.statusText + '<br/>');
    	}
    }
    If you have issues with your .hasAttr plugin then I can post the entirety of the working code I have used that does not use hasAttr.js. Also, you need to trust that your data from this API will never be malicious. If you are concerned about this then I suggest finding a good JSON parser to use instead of eval().

    Regards,
    Stephen
    Last edited by sperelson; 2012-04-04 at 16:30.

  5. #5
    Registered User
    Join Date
    Mar 2012
    Posts
    11

    Re: Using Longman Dictionary API

    Hi Stephan first of all i would like to thank you for your reply. when i replcaed my doSearch(searchFor) method with your given code. i am getting a error network error.
    Please give me the full working code or help me to resolve this problem.
    Any Suggestion/help must be appreciated.

    Thanks in Advance.

  6. #6
    Registered User
    Join Date
    Jun 2008
    Location
    Port Elizabeth, South Africa
    Posts
    37

    Re: Using Longman Dictionary API

    Hi,

    Now it does not sound like an error with the code behind the XMLHttpRequest. Please double check your searchUrl and other variables.

    Also make sure that the simulator and your handset can each reach the called page. You can do this by just putting a link into the html of the html file of your project:
    Code:
    <a href="https://api.pearson.com/longman/dictionary/0.1/entry?apikey=YOURAPIKEY&q=cat">Test Link</a>
    Replace "YOURAPIKEY" with your api key.

    Clicking this link when doing a Cloud Preview or running on the handset should load some of the results from the Longman service. If it does not then your error is definitely that your network is preventing access to the service for some reason.

    I will post the full code I used later when I get a chance.

    Regards,
    Stephen

  7. #7
    Registered User
    Join Date
    Mar 2012
    Posts
    11

    Re: Using Longman Dictionary API

    Hi Stephen Thnaks for your response.while i am accssing by your given link getting error like
    Error code-407 Proxy Authentication Required.The ISA server requires authorization to fulfill the request.

    Any help must be appriciated.

    Thnaks in Advance.

  8. #8
    Registered User
    Join Date
    Jun 2008
    Location
    Port Elizabeth, South Africa
    Posts
    37

    Re: Using Longman Dictionary API

    Hi,

    That is definitely an issue on your side. It looks like you are using a computer at work and they have an Internet Security and Acceleration (ISA) Server (a Microsoft product if I am not mistaken) to manage everyone's Internet connections. That ISA server requires authentication with a user name and password. Your computer's web browsers are already configured and authenticate through the ISA server properly so they can connect out and seem to work properly.

    The Web App simulator may not be configured to route through the ISA server. There are settings that you can set, but it may not work. I could not see where in the simulator the username and password could be set. Setting it to use the System Proxy should work unless your computer does not have a system-wide proxy set up.

    Do you deploy the web app and enter the giving URL into the phone's Nokia Browser for testing? Does that phone connect via your cellular network or via Wifi? If you are connecting via Wifi then it is also getting caught by the ISA server.

    You will either have to test your web app on a phone with the Nokia Browser connecting directly to the Internet with a cell data connection and not on Wifi.

    Or, maybe you can get someone to put a rule into the ISA server to allow full access to the various Nokia Proxy server addresses. With these servers open to you, you should have no more issues when you are testing behind that ISA server.

    The servers you would need access to are:
    • dev-wam.browser.ovi.com
    • dev-cloud1.browser.ovi.com

    Maybe one of the mods could double check this information to make sure it is right.

    Regards,
    Stephen

Similar Threads

  1. T9 Dictionary
    By patlucas in forum Python
    Replies: 1
    Last Post: 2010-06-29, 13:49
  2. N97 Dictionary
    By mohitrb1 in forum Mobile Java General
    Replies: 1
    Last Post: 2010-03-01, 20:16
  3. Replies: 3
    Last Post: 2008-12-23, 12:02
  4. T9 Dictionary
    By lavanya_sep in forum Mobile Java General
    Replies: 2
    Last Post: 2005-08-04, 12:04
  5. T9 Dictionary
    By nishantsaxena in forum PC Suite API and PC Connectivity SDK
    Replies: 1
    Last Post: 2003-09-17, 18:08

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •