JavaScript API Overview (v0.8)

From OpenSocial

Jump to: navigation, search

Contents

This page covers some of the major areas of the OpenSocial JavaScript API.

Requesting Data

Apps can ask the container for social data, like a user's name or photo, by sending a DataRequest. Apps can also request content from other servers by using the makeRequest function.

Social Data

To request social data, first create a new opensocial.DataRequest, add request items to it, and send it to the container.

Related Functions
opensocial.newDataRequest()
opensocial.DataRequest.add()
opensocial.DataRequest.newFetchPersonRequest()
opensocial.DataRequest.newFetchPeopleRequest()
opensocial.DataRequest.send()
opensocial.newIdSpec()

When the container has processed your request, the callback method you provided to the send() function will be invoked with an opensocial.DataResponse as the only parameter.

Related Classes and Functions
opensocial.DataResponse
hadError()
get()
opensocial.ResponseItem
hadError()
getData()
opensocial.Collection

Remote Data

To send a HTTP request to another server, use gadgets.io.makeRequest. There are a number of optional parameters you can send to the makeRequest function to control the content of the request and the response.

Related Classes and Functions
gadgets.io.makeRequest()
gadgets.io.requestParameters.METHOD
gadgets.io.requestParameters.CONTENT_TYPE
gadgets.io.requestParameters.AUTHORIZATION

Person Objects and Fields

A user's profile data is contained in an opensocial.Person object. Some profile fields are represented by classes to preserve the structure of the data.

Related Classes and Functions
opensocial.Person
opensocial.Address
opensocial.BodyType
opensocial.Email
opensocial.Enum
opensocial.Name
opensocial.Organization
opensocial.Phone
opensocial.Url

Viral Channels

OpenSocial defines three ways for your app to spread between users: activities, messages, and invitations.

Activities

When a user performs an action within your app, you can post this as an activity so the user's friends can see what they're up to.

Related Classes and Functions
opensocial.requestCreateActivity()
opensocial.newMediaItem()
opensocial.Activity
opensocial.CreateActivityPriority
opensocial.MediaItem

Messages

Sometimes users want to share info with a specific friend (or group of friends) by sending messages.

Related Classes and Functions
opensocial.requestSendMessage
opensocial.Message

Invitations

If a user really likes your app, you can let them share it with their friends.

Related Classes and Functions
opensocial.requestShareApp
opensocial.NavigationParameters

Capability Discovery

Not all containers support the same functionality or profile fields, so OpenSocial provides a way for your app to discover what is available.

Profile Field Support

You can ask the container if it supports a specific profile field (e.g. movies, interests, etc.)

Related Classes and Functions
opensocial.getEnvironment
opensocial.Environment
supportsField()

Feature Support

You can ask the container if it support a specific feature (e.g. tabs, views, etc.)

Related Classes and Functions
gadgets.util.hasFeature()
gadgets.util.getFeatureParameters()

Permissions

You can ask the ocntainer if your app has permission to perform an action (e.g. post activity, send message, etc.)

Related Classes and Functions
opensocial.requestPermission
opensocial.hasPermission
opensocial.Permission


OpenSocial 0.8

gadgets.flash

gadgets.io

gadgets.json

gadgets.MiniMessage

gadgets.Prefs

gadgets.pubsub

gadgets.rpc

gadgets.skins

gadgets.Tab

gadgets.TabSet

gadgets.util

gadgets.views

gadgets.window

opensocial

opensocial.Activity

opensocial.Address

opensocial.BodyType

opensocial.Collection

opensocial.CreateActivityPriority

opensocial.DataRequest

opensocial.DataResponse

opensocial.Email

opensocial.Enum

opensocial.Environment

opensocial.EscapeType

opensocial.IdSpec

opensocial.MediaItem

opensocial.Message

opensocial.Name

opensocial.NavigationParameters

opensocial.Organization

opensocial.Permission

opensocial.Person

opensocial.Phone

opensocial.ResponseItem

opensocial.Url

Personal tools