Welcome Developers!

in

Welcome!

in

makeRequest is consistantly returning null values

Last post 04-18-2009 4:06 PM by City of Angels is IN!. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 04-12-2009 6:28 PM

    makeRequest is consistantly returning null values

    The following is the code in that I am having trouble with. The problems is that no matter what url I toss in there....  I always return null data. I can even comment out all the peramiters so that it goes to default settings. No matter what, same results. Please help.

    I am using 0.8 api, firefox is my browser.

    <div id='heading'></div>
    <hr size="1px" />
     
    <script type="text/javascript">
     
    // the entry point for the app, fired from the onload handler.
    function init(){
        // create the opensocial.DataRequest object.
        var request = opensocial.newDataRequest();
     
        // create a list of Person fields to fetch,
        // in this case, include all supported fields.
        var fields = [opensocial.Person.Field.ID];
     
        // add the supported fields to the parameter list.
        var params = new Object();
        params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = fields;
     
        // add the fetch person request to the queue.
        request.add(request.newFetchPersonRequest(opensocial.IdSpec.PersonId.VIEWER, params), "the_viewer");
     request.add(request.newFetchPersonRequest(opensocial.IdSpec.PersonId.OWNER, params), "the_owner");
        // start executing the requests, call back into got_init when done.
        request.send(got_init);
    };

     function makeRequest(url, postdata) {
       var params = new Object();
       postdata = gadgets.io.encodeValues(postdata);
       params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.OAUTH;
       params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
       params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
       params[gadgets.io.RequestParameters.POST_DATA]= postdata;
       gadgets.io.makeRequest(url, response, params);
     };

    function response(obj) {
    document.getElementById('heading').innerHTML = obj.data;
    };

        function got_init(response){
            var parse_person = true;
            if(parse_person){
                // get the opensocial.Person object from the other opensocial.ResponseItem and save it to a global variable.
                person = response.get("the_viewer").getData();
                owner = response.get("the_owner").getData();

                //get viewerid and ownerid and parse string
                var viewerId = person.getId().substr(12, person.getId().length);
                var ownerId = owner.getId().substr(12, person.getId().length);

                var data = {
                   viewer : 7,
                   owner : 15           
                };

                makeRequest("secret", data);

            }
    };


    gadgets.util.registerOnLoadHandler(init);
    </script>

  • 04-13-2009 4:44 AM In reply to

    Re: makeRequest is consistantly returning null values

     I'll check into it.

  • 04-14-2009 8:43 PM In reply to

    Re: makeRequest is consistantly returning null values

     Thank you very much, I appreciate it. I'm really looking forward to your response.

  • 04-15-2009 3:10 PM In reply to

    Re: makeRequest is consistantly returning null values

     Okay, So I found that it works if I change the code from being a div to being an iframe.

     Should I then just copy the iframe contents to the div over, I mean, that a bit oldschool ajax, no?

     My question is, should it work in directly into a div, or not?

  • 04-15-2009 4:50 PM In reply to

    Re: makeRequest is consistantly returning null values

     Hey I have not heard back, let me follow up thanks!

  • 04-17-2009 10:43 AM In reply to

    Re: makeRequest is consistantly returning null values

    Hi, your code looks correct, and yes, you should be able to write directly to a div.  I suggest installing Firebug to determine exactly what data, if any, is coming back from the makeRequest call.

    Failing that, you could also check for an error coming back in your response function, in obj.errors, obj.errorCode or obj.errorMessage.  If you message me the URL you're trying to hit I can test as well (http://www.myspace.com/cdsrussell).

    Chad

  • 04-17-2009 11:36 AM In reply to

    Re: makeRequest is consistantly returning null values

     Hey chad. There are no errors comming back, just the data is comming back undefined.

     as far as the firebug thing, I mean, I have it installed, but, I'm not gonna lie, when I load the canvas and with the debugger on, or the profile, I have so much js going on that I can't even find my variables.

  • 04-17-2009 11:49 AM In reply to

    Re: makeRequest is consistantly returning null values

    Okay, so this is what I am getting back.. line for line, formatted nicely. I still have no idea what's happening, any advice?

     

    <iframe

    id="apppanel_132261_canvas"

    name="apppanel_132261_canvas"

    src="http://api.msappspace.com/apprendering/04172009114154/1_0_0/render.app

    ?opensocial_token=f7k%2fKgLiqYMRkR2rXWcr8W57RZtYCIBC2NRH%2bdlRuqkWza93YbZgYiXI1ALaXPjekpxlUw1fuqFijrdtbgbIaqE%2bd%2bCP6P%2fqvK2Wm3bWSus%3d

    &opensocial_surface=canvas

    &perm=%5b%22DP%22%2c%22UT%22%2c%22UF%22%2c%22RN%22%2c%22PB%22%2c%22SN%22%2c%22%22%5d&ownerId=463540855

    &viewerId=463540855

    &installState=1

    &country=ca

    &lang=en

    &mc=UOC%2cECC%2cRSAMR"

    width="100%" height="1000" scrolling="no" frameborder="0" allowtransparency="true" style="border: none; background:transparent;"></iframe><br />

     
     <script type="text/javascript">
     var MySpaceAppProfileContext = { appId: "132261" ,
    token:"I9F21Vlxcq0quoSd2%2bHjVYClHfYc3APOprI86WspxsX7yUZ8VDn5yjRsRY8r9QA6f%2boxtiVYQbMAgKFpg1U%2fXDP%2fySz%2fHPTXyxy%2fKqAzFLE%3d", loginUrl: "http://www.myspace.com",
    appDisplayName: "Thug Life" };
     </script>
  • 04-17-2009 1:10 PM In reply to

    Re: makeRequest is consistantly returning null values

    I don't think that's the response from the makeRequest call, it looks like the markup from the parent page.  Your app will be running inside that iframe.

    To get Firebug working I suggest right clicking your app, This Frame --> Open frame in new tab, then work from there, a lot less JS will be on the page.  Then set a breakpoint in your callback function and take a look at what the obj variable looks like.

  • 04-18-2009 8:15 AM In reply to

    Re: makeRequest is consistantly returning null values

    Ok, So first I wanted to thank you Chad for your help and your patience.

     

    I did what you told me, that is a great way to debug. I decided to also cut the fat and get to the root of the problems, so I took out most of the unnessasary code. firbug is telling me that dataObj errorcode=badrequest.

    yet, the code is pretty much copy pasted from the documentation. The following is the js. 

    here is my js:

    <div id="AppBody" scrolling="no" style="width: 960px; min-height:1000px; overflow:auto; float:left;"> </div>
    <script type="text/javascript">

        server_url="http://99.238.66.75/thuglife/myspace/www/response2.php";
       
        function makeGetRequest(url) {
            var params = new Object();
            var d = new Date();
            params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;
            url = url + '?d=' + d.getTime();
            var k = gadgets.io.makeRequest(url, response, params);
        }
       
        function makePostRequest(url, postData) {
            var params = new Object();
            var d = new Date();
            postData = gadgets.io.encodeValues(postData);
            params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
            params[gadgets.io.RequestParameters.POST_DATA] = postData;
            url = url + '?d=' + d.getTime();
            var k = gadgets.io.makeRequest(url, response, params);
        }
       
        function response(dataObj) {
            var newData = dataObj.text + "</br>";
            newData = newData + dataObj.errors + "</br>";
            newData = newData + dataObj.data + "</br>";
            newData = newData + dataObj.oauthApprovalUrl + "</br>";
            newData = newData + dataObj.oauthError + "</br>";
            newData = newData + dataObj.oauthErrorText + "</br>";
            document.getElementById("AppBody").innerHTML = newData;
        }
       
        var data = {
            data1 : "test",
            data2 : 123456
        };
       
        window.onload(makeGetRequest(server_url));

    </script>

    here is my server side script:

    <?php
        // Includes
        error_reporting (E_ALL);
        require_once("/var/www/thuglife/myspace/client/Config.php");
        require_once("/var/www/thuglife/myspace/client/MySpaceAPI.php");
        require_once("/var/www/thuglife/myspace/client/Common.php");
        require_once("/var/www/thuglife/myspace/client/MyOpenSpaceAPI.php");
         // <-- SET YOUR KEY/SECRET HERE
        error_reporting (E_ALL || E_STRICT);
        // Set the key - application uri - secret key
        $myspace = new MySpaceAPI(Config::$APPLICATION_KEY, Config::$APPLICATION_SECRET);
        // Get XML, JSON
        //$myspace->set_output_array(false); //set to false to get the XML or JSON format instead of native php arrays
        //$myspace->set_response_type(ResponseType::$JSON); //change the type to XML, JSON
       
        //--------------------------------------------------------------------
        print_r ($_GET);
        print_r($_POST);

    ?>

     

    here is my printout output:

    undefined
    undefined
    undefined
    undefined
    undefined
    undefined

     

    Thank you very much for your help in advance.

    Filed under:
  • 04-18-2009 4:06 PM In reply to

    Re: makeRequest is consistantly returning null values

     Okay, Thank you muchly, The issue has been solved. Apperently I needed a domain name, rather than just my server ip address (so I needed to register for one) Changed that and it works fine. The need to document this better

Page 1 of 1 (11 items)