Useful OpenSocial Functions

From Triangle Wiki

Jump to: navigation, search

makeRequest()

opensocial.makeRequest(url,callback,opt_param) opensocial.Container.get().makeRequest(url,callback,opt_param)

Only port 80 is available at the moment.

  • url

The url you wish to be called.

  • callback(data)

The function you wish to be called with the results. The signature of the function should have at least one parameter (which will contain a reference to the data returned by the call).

  • opt_param

A bucket for a set of standard OpenSocial parameters that tell the proxy how to behave. There is quite a bit of functionality accessible through the manipulation of this object.

In development (18/2/08): pass ContentRequestParameters.AuthenticationType.SIGNED into your makeRequest call. Doing so will cause OAUTH to digitally sign the request and will allow you to verify the identity of the viewer and owner.

Below is some example code that exercises opt_param to its fullest.

Example

  1. var params = {};
  2.  
  3. // Lets makeRequest know that the result will be an XML document.
  4. params[opensocial.ContentRequestParameters.CONTENT_TYPE] =
  5. opensocial.ContentRequestParameters.ContentType.XML;
  6.  
  7. // Sets the request method to POST (default is GET).
  8. params[opensocial.ContentRequestParameters.METHOD] =
  9. opensocial.ContentRequestParameters.MethodType.POST;
  10.  
  11. // Adds two custom headers to the request. These headers will be passed on to the target.
  12. params[opensocial.ContentRequestParameters.HEADERS] =
  13. {"x-myheader":"myheadervalue", "x-myotherheader":"myotherheadervalue"};
  14.  
  15. // Tells the proxy to sign the request using OAuth.
  16. params[opensocial.ContentRequestParameters.AUTHORIZATION] =
  17. opensocial.ContentRequestParameters.AuthorizationType.SIGNED;
  18.  
  19. opensocial.makeRequest(url, makeRequest_callback, params);

DataRequest()

ToDo

Navigation

Edit Navigation

Personal tools