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

Javascript

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 Posters 694 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 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?
    jsulmJ 1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on 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
      1
      • A Abdulmueez

        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?
        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on 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
        • Kent-DorfmanK Kent-Dorfman

          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 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

          aha_1980A 1 Reply Last reply
          1
          • A Abdulmueez

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

            aha_1980A Offline
            aha_1980A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on 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 last edited by
              #6

              How do I go about that please

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on 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

                • Login

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