Welcome Developers!

in

Welcome!

in

No makeRequest examples work

Last post 08-07-2009 1:11 PM by kai. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 08-05-2009 5:05 PM

    • kai
    • Not Ranked
    • Joined on 08-05-2009
    • Posts 5

    No makeRequest examples work

    Not sure if I'm just a fool here, but I am having a hard time finding any information on makeRequest that's useful. The latest example that actually does something, albeit just an error, is this: function init() { var geturl = "http://www.w3.org"; var target = document.getElementById('heading'); var os_params = {}; try { os_params[opensocial.ContentRequestParameters.METHOD] = opensocial.ContentRequestParameters.MethodType.GET; opensocial.Container.get().makeRequest(geturl, makeRequest_Callback, os_params); }catch(er){ target.style.backgroundColor = '#f00'; target.style.color = '#fff'; target.innerHTML = er.message; } } function makeRequest_Callback(response, url, errored) { if (!errored) { target.innerHTML = "
    " + response; } else { target.innerHTML = 'error: ' + errored ; } } init(); The error I get is: Cannot read property 'METHOD' of undefined Basically, all I want to do is be able to send and receive data to and from my host site. This should not be a hard thing to do since it is very common in the majority of applications out there. Why then is there no solid documentation for this? Or is there? Maybe I just have the wrong function. Does anyone else have this problem? Or do you know of a functional way to contact your app's host?
    Filed under:
  • 08-07-2009 12:17 PM In reply to

    • Chak
    • Top 50 Contributor
    • Joined on 01-13-2008
    • Posts 73

    Re: No makeRequest examples work

    The code you have above is related to OpenSocial 0.7. I'm guessing the app is set to 0.8 (it's set to 0.8 by default when the app is created). You should keep the app as 0.8 and refer to the link below for more info. on using makerequest in an 0.8 environment. http://wiki.opensocial.org/index.php?title=Introduction_to_makeRequest#Calling_makeRequest Chak
  • 08-07-2009 1:11 PM In reply to

    • kai
    • Not Ranked
    • Joined on 08-05-2009
    • Posts 5

    Re: No makeRequest examples work

    Thanks. I eventually figured it out through a long process of searching.

    Though I am not exactly sure about how to verify the request is coming from myspace in a secure way. I downloaded the SDK, which looks to be a large library of standard methods I don't particularly need.

    You can request auth tokens, but when it comes to verifying them, the user is presented with an approval page? Is this serious? Didn't they approve it when they installed the app? All I want to do is verify the request is from myspace, then get the user id of the owner of the app and the viewer of the app to compare. Is it really that hard?

    I see a lot of responses here are plain and simply: check out our SDK... I don't know about anyone else, but that is not of much use to me to be handed an sdk and have to audit the code to figure it out. The documentation I found is basically the walkthrough, which provides the example app, which also does the login thing I want to avoid.

    Is there a useful documentation anywhere? Or just an answer to how I can authorize the request, and get owner and viewer ids?



    solution to original problem: var os; var dataRequest; dataRequestLine(doMakeRequest); function dataRequestLine(method) { os = opensocial.Container.get(); dataRequest = os.newDataRequest(); var param = {}; param[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [; var OWNERReq = os.newFetchPersonRequest(opensocial.IdSpec.PersonId.OWNER, param); var VIEWERReq = os.newFetchPersonRequest(opensocial.IdSpec.PersonId.VIEWER, param); dataRequest.add(VIEWERReq, "get_viewer"); dataRequest.add(OWNERReq, "get_owner"); dataRequest.send(method); } function doMakeRequest(owner_id, viewer_id) { var param = {}; param[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.HTML; param[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST; param[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED; param[gadgets.io.RequestParameters.POST_DATA] = {"action":"some_request", "vid":viewer_id, "oid":owner_id}; gadgets.io.makeRequest("http://somedomain.com", gotMakeRequest, param); } function gotMakeRequest(response, url, errored) { if(!errored) { c.innerHTML = response.text; } else { c.appendChild(document.createTextNode("makeRequest failed:(" + response + ")(" + url + ")(" + errored + ")" + "\r\n")); } }

    What, <code> tags don't work? how are people posting code here?
Page 1 of 1 (3 items)