Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Javascript
Forum Update on Monday, May 27th 2025

Javascript

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 Posters 696 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abdulmueez
    wrote on 18 Jul 2019, 14:08 last edited by
    #1

    I am new to javascript and qml, I am currently working on a task I found online. Here is the javascript function.

    function request() {
            var base = "https://api.themoviedb.org/4/list/1?api_key=c2bfbeddbb087523d43eb817f5c7d40d"
            var access_token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjMmJmYmVkZGJiMDg3NTI
            zZDQzZWI4MTdmNWM3ZDQwZCIsInN1YiI6IjVkMmY1MDdlMjdkOWNjNDE2ZDdiZDQ2OCIsInNjb3BlcyI6WyJhcGlf
            cmVhZCJdLCJ2ZXJzaW9uIjoxfQ.VL4AzMrddLht-8LAOGOtwlyajkJSfXX2hJj6Es7nfWg"
            var xhr = new XMLHttpRequest();
            xhr.open("GET", base);
            xhr.setRequestHeader("authorization","Bearer <<access_token>>")
            xhr.onreadystatechange = function() {
                if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
                    print('HEADERS_RECEIVED')
                } else if(xhr.readyState === XMLHttpRequest.DONE) {
                    print('DONE')
                    var json = JSON.parse(xhr.responseText.toString())
                    for(var i = 0; i<json.results.length;i++){
                        movieModel.append({"imageUrl": base + json.results[i].poster_path,"name":json.
                        results[i].original_title,"date": json.results[i].release_date,"stars":json.results[i].vote_average})
                    }
                }
            }
            xhr.send();
        }
    ```.
    Everything works fine , except for the imageUrl where I am getting the error 
    

    QML Image: Host requires authentication

    From what i could find, the error might be due to the fact that im using the base url in constructing the url of the image. I should use the url of that point in the website. Can someone help me out please?
    J 1 Reply Last reply 19 Jul 2019, 04:30
    0
    • K Offline
      K Offline
      Kent-Dorfman
      wrote on 19 Jul 2019, 04:05 last edited by
      #2

      I don't see anythin in your code that makes this a Qt or QML issue, but to be fair, I don't know QML. It seems to me to be a pure javascript debugging issue.

      A 1 Reply Last reply 20 Jul 2019, 10:08
      1
      • A Abdulmueez
        18 Jul 2019, 14:08

        I am new to javascript and qml, I am currently working on a task I found online. Here is the javascript function.

        function request() {
                var base = "https://api.themoviedb.org/4/list/1?api_key=c2bfbeddbb087523d43eb817f5c7d40d"
                var access_token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjMmJmYmVkZGJiMDg3NTI
                zZDQzZWI4MTdmNWM3ZDQwZCIsInN1YiI6IjVkMmY1MDdlMjdkOWNjNDE2ZDdiZDQ2OCIsInNjb3BlcyI6WyJhcGlf
                cmVhZCJdLCJ2ZXJzaW9uIjoxfQ.VL4AzMrddLht-8LAOGOtwlyajkJSfXX2hJj6Es7nfWg"
                var xhr = new XMLHttpRequest();
                xhr.open("GET", base);
                xhr.setRequestHeader("authorization","Bearer <<access_token>>")
                xhr.onreadystatechange = function() {
                    if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
                        print('HEADERS_RECEIVED')
                    } else if(xhr.readyState === XMLHttpRequest.DONE) {
                        print('DONE')
                        var json = JSON.parse(xhr.responseText.toString())
                        for(var i = 0; i<json.results.length;i++){
                            movieModel.append({"imageUrl": base + json.results[i].poster_path,"name":json.
                            results[i].original_title,"date": json.results[i].release_date,"stars":json.results[i].vote_average})
                        }
                    }
                }
                xhr.send();
            }
        ```.
        Everything works fine , except for the imageUrl where I am getting the error 
        

        QML Image: Host requires authentication

        From what i could find, the error might be due to the fact that im using the base url in constructing the url of the image. I should use the url of that point in the website. Can someone help me out please?
        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 19 Jul 2019, 04:30 last edited by jsulm
        #3

        @Abdulmueez said in Javascript:

        I am getting the error

        What error?

        "xhr.setRequestHeader("authorization","Bearer <<access_token>>")" - I'm really not an JavaScript expert, but shouldn't you put the content of access_token into the second string? Because now second parameter is just "Bearer <<access_token>>" string, it does not contain the actual token.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • K Kent-Dorfman
          19 Jul 2019, 04:05

          I don't see anythin in your code that makes this a Qt or QML issue, but to be fair, I don't know QML. It seems to me to be a pure javascript debugging issue.

          A Offline
          A Offline
          Abdulmueez
          wrote on 20 Jul 2019, 10:08 last edited by
          #4

          @Kent-Dorfman Yes, it was a javascript issue, already fixed it, the url for the image is different. Thanks a lot

          A 1 Reply Last reply 20 Jul 2019, 14:53
          1
          • A Abdulmueez
            20 Jul 2019, 10:08

            @Kent-Dorfman Yes, it was a javascript issue, already fixed it, the url for the image is different. Thanks a lot

            A Offline
            A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on 20 Jul 2019, 14:53 last edited by
            #5

            @Abdulmueez So please mark this topic as SOLVED then. Thanks!

            Qt has to stay free or it will die.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Abdulmueez
              wrote on 20 Jul 2019, 20:06 last edited by
              #6

              How do I go about that please

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 20 Jul 2019, 20:43 last edited by
                #7

                Hi,

                Click on the "Topic Tools" button and you'll have the option.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0

                1/7

                18 Jul 2019, 14:08

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved