Opensocial (v0.8)
From OpenSocial
![]() |
This page has example code which needs to be improved. Please help improve this page by fixing existing code or writing additional examples. (November 2008) |
opensocial
Namespace for top level functions.
Methods
opensocial.requestSendMessage
opensocial.requestSendMessage(recipients, message, opt_callback, opt_params)- Parameters
Array.<String> | String recipients- An ID, array of IDs, or a group reference; the supported keys are VIEWER, OWNER, VIEWER_FRIENDS, OWNER_FRIENDS, or a single ID within one of those groupsopensocial.Message message- The message to send to the specified usersFunction opt_callback- The function to call once the request has been processed; either this callback will be called or the gadget will be reloaded from scratchopensocial.NavigationParameters opt_params- The optional parameters indicating where to send a user when a request is made, or when a request is accepted; options are of type NavigationParameters.DestinationType- Returns
- None
Examples
This example shows how to send an email using OpenSocial.
function sendEmail(title, body) { var params = []; params[opensocial.Message.Field.TITLE] = title; params[opensocial.Message.Field.TYPE] = opensocial.Message.Type.EMAIL; var message = opensocial.newMessage(body, params); var recipient = "VIEWER"; opensocial.requestSendMessage(recipient, message, callback); }; function callback(data) { if (data.hadError()) { alert("There was a problem:" + data.getErrorCode()); } else { output("Ok"); } }; sendEmail("This is a test email", "How are you doing?");
opensocial.requestShareApp
opensocial.requestShareApp(recipients, reason, opt_callback, opt_params)- Parameters
Array.<String> | String recipients- An ID, array of IDs, or a group reference; the supported keys are VIEWER, OWNER, VIEWER_FRIENDS, OWNER_FRIENDS, or a single ID within one of those groupsopensocial.Message reason- The reason the user wants the gadget to share itself. This reason can be used by the container when prompting the user for permission to share the app. It may also be ignored.Function opt_callback- The function to call once the request has been processed; either this callback will be called or the gadget will be reloaded from scratchopensocial.NavigationParameters opt_params- The optional parameters indicating where to send a user when a request is made, or when a request is accepted; options are of type opensocial.NavigationParameters- Returns
- None
opensocial.requestCreateActivity
opensocial.requestCreateActivity(activity, priority, opt_callback)
opensocial.hasPermission
opensocial.hasPermission(permission)- Parameters
opensocial.Permission permission- The permission- Returns
Boolean- True if the gadget has access for the permission; false if it doesn't
Examples
This code snippet checks to see if the current gadget has permission to the viewer object for the current container
if(opensocial.hasPermission(opensocial.Permission.VIEWER )) { output("You have permission to viewer object"); } else { output("You don't have permissions to viewer object"); }
opensocial.requestPermission
opensocial.requestPermission(permissions, reason, opt_callback)- Parameters
Array.<opensocial.Permission> permissions- The permission to request from the viewerString reason- Displayed to the user as the reason why these permissions are neededFunction opt_callback- The function to call once the request has been processed; either this callback will be called or the gadget will be reloaded from scratch. This function will be passed one parameter, an opensocial.ResponseItem. The error code will be set to reflect whether there were any problems with the request. If there was no error, all permissions were granted. If there was an error, you can use opensocial.hasPermission to check which permissions are still denied. The data on the response item will be set. It will be an array of the opensocial.Permissions that were granted.- Returns
- None
opensocial.getEnvironment
opensocial.getEnvironment()- None
- Returns
opensocial.Environment- The current environment
opensocial.newDataRequest
opensocial.newDataRequest()- None
- Returns
opensocial.DataRequest- The DataRequest object
Examples
This code snippet fetches some of the current viewer's detailed information: display name, thumbnail image link, and other fields such as "About Me" and "Status"
function response(data) { var viewer = data.get("viewer_profile").getData(); var aboutme = viewer.getField(opensocial.Person.Field.ABOUT_ME); var status = viewer.getField(opensocial.Person.Field.STATUS); var img = viewer.getField(opensocial.Person.Field.THUMBNAIL_URL); output("AboutMe:" + aboutme); output("STATUS: " + status); output('<img src="' + img +'">'); var name = viewer.getDisplayName(); output(name); }; function request() { var req = opensocial.newDataRequest(); var params = {}; params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [ opensocial.Person.Field.ABOUT_ME, opensocial.Person.Field.STATUS, opensocial.Person.Field.THUMBNAIL_URL ]; req.add(req.newFetchPersonRequest("VIEWER", params), "viewer_profile"); req.send(response); }; request();
opensocial.newActivity
opensocial.newActivity(params)- Parameters
Map.<opensocial.Activity.Field, Object> params- Parameters defining the activity- Returns
opensocial.Activity- The new activity object
opensocial.newMediaItem
opensocial.newMediaItem(mimeType, url, opt_params)- Parameters
String mimeType- MIME type of the mediaString url- Where the media can be foundMap.<opensocial.MediaItem.Field, Object> opt_params- Any other fields that should be set on the media item object; all of the defined MediaItem fields are supported- Returns
opensocial.MediaItem- The new media item object
opensocial.newMessage
opensocial.newMessage(body, opt_params)
Examples
This example shows how to send an email using OpenSocial.
function sendEmail(title, body) { var params = []; params[opensocial.Message.Field.TITLE] = title; params[opensocial.Message.Field.TYPE] = opensocial.Message.Type.EMAIL; var message = opensocial.newMessage(body, params); var recipient = "VIEWER"; opensocial.requestSendMessage(recipient, message, callback); }; function callback(data) { if (data.hadError()) { alert("There was a problem:" + data.getErrorCode()); } else { output("Ok"); } }; sendEmail("This is a test email", "How are you doing?");
opensocial.newIdSpec
opensocial.newIdSpec(params)- Parameters
Map.<opensocial.IdSpec.Field, Object> parameters- Parameters defining the id spec.- Returns
opensocial.IdSpec- The new IdSpec object
opensocial.newNavigationParameters
opensocial.newNavigationParameters(params)- Parameters
Map.<opensocial.NavigationParameters.Field, Object> parameters- Parameters defining the navigation- Returns
opensocial.NavigationParameters- The new NavigationParameters object
|
OpenSocial 0.8 |
|||
|
opensocial |
|||

