English | Site Directory

opensocial.DataRequest (v0.6)

 SUMMARY     DETAIL

Class opensocial.DataRequest

Creates an item to request social information from the container. This includes data for friends, profiles, app data, and activities. All apps that require access to people information should send a DataRequest.

Here's an example of creating, initializing, sending, and handling the results of a data request:

function requestMe() {
  var req = opensocial.newDataRequest();
  req.add(req.newFetchPersonRequest(
            opensocial.DataRequest.PersonId.VIEWER),
          "viewer");
  req.send(handleRequestMe);
};

function handleRequestMe(data) {
  var viewer = data.get("viewer");
  if (viewer.hadError()) {
    //Handle error using viewer.getError()...
    return;
  }

  //No error. Do something with viewer.getData()...
}

See also: opensocial.newDataRequest()

Method Summary

add(request, opt_key)
Adds an item to fetch (get) or update (set) data from the server.
 Object newFetchActivitiesRequest(idSpec, opt_params)
Creates an item to request an activity stream from the server.
 Object newFetchGlobalAppDataRequest(keys)
Creates an item to request global app data.
 Object newFetchInstanceAppDataRequest(keys)
Creates an item to request instance app data.
 Object newFetchPeopleRequest(idSpec, opt_params)
Creates an item to request friends from the server.
 Object newFetchPersonAppDataRequest(idSpec, keys)
Creates an item to request app data for the given people.
 Object newFetchPersonRequest(id, opt_params)
Creates an item to request a profile for the specified person ID.
 Object newUpdateInstanceAppDataRequest(key, value)
Creates an item to request an update of an app instance field from the server.
 Object newUpdatePersonAppDataRequest(id, key, value)
Creates an item to request an update of an app field for the given person.
send(opt_callback)
Sends a data request to the server in order to get a data response.
 

Method Detail

add

add(request, opt_key)
    Adds an item to fetch (get) or update (set) data from the server. A single DataRequest object can have multiple items. As a rule, each item is executed in the order it was added, starting with the item that was added first. However, items that can't collide might be executed in parallel.
    Parameters:
      Object request - Specifies which data to fetch or update
      String opt_key - A key to map the generated response data to

newFetchActivitiesRequest

Object newFetchActivitiesRequest(idSpec, opt_params)
    Creates an item to request an activity stream from the server.

    When processed, returns an object where "activities" is a Collection<Activity> object.

    Parameters:
      Array.<String>, String idSpec - An ID, array of IDs, or a group reference to fetch activities for
      Map.<opensocial.DataRequest.ActivityRequestFields, Object> opt_params - Additional parameters to pass to the request
    Returns:
      Object A request object

newFetchGlobalAppDataRequest

Object newFetchGlobalAppDataRequest(keys)
    Creates an item to request global app data. When processed, returns a Map<String, String> object.
    Parameters:
      Array.<String>, String keys - The keys you want data for; this can be an array of key names, a single key name, or "*" to mean "all keys"
    Returns:
      Object A request object

newFetchInstanceAppDataRequest

Object newFetchInstanceAppDataRequest(keys)
    Creates an item to request instance app data. When processed, returns a Map<String, String> object.
    Parameters:
      Array.<String>, String keys - The keys you want data for; this can be an array of key names, a single key name, or "*" to mean "all keys"
    Returns:
      Object A request object

newFetchPeopleRequest

Object newFetchPeopleRequest(idSpec, opt_params)
    Creates an item to request friends from the server. When processed, returns a Collection <Person> object.
    Parameters:
      Array.<String>, String idSpec - An ID, array of IDs, or a group reference used to specify which people to fetch
      Map.<opensocial.DataRequest.PeopleRequestFields, Object> opt_params - Additional params to pass to the request
    Returns:
      Object A request object

newFetchPersonAppDataRequest

Object newFetchPersonAppDataRequest(idSpec, keys)
    Creates an item to request app data for the given people. When processed, returns a Map< PersonId>, Map<String, String>> object.
    Parameters:
      Array.<String>, String idSpec - An ID, array of IDs, or a group reference; the supported keys are VIEWER, OWNER, OWNER_FRIENDS, or a single ID within one of those groups
      Array.<String>, String keys - The keys you want data for; this can be an array of key names, a single key name, or "*" to mean "all keys"
    Returns:
      Object A request object

newFetchPersonRequest

Object newFetchPersonRequest(id, opt_params)
    Creates an item to request a profile for the specified person ID. When processed, returns a Person object.
    Parameters:
      String id - The ID of the person to fetch; can be the standard person ID of VIEWER or OWNER
      Map.<opensocial.DataRequest.PeopleRequestFields, Object> opt_params - Additional parameters to pass to the request; this request supports PROFILE_DETAILS
    Returns:
      Object A request object

newUpdateInstanceAppDataRequest

Object newUpdateInstanceAppDataRequest(key, value)
    Creates an item to request an update of an app instance field from the server. When processed, does not return any data.
    Parameters:
      String key - The name of the key
      String value - The value
    Returns:
      Object A request object

newUpdatePersonAppDataRequest

Object newUpdatePersonAppDataRequest(id, key, value)
    Creates an item to request an update of an app field for the given person. When processed, does not return any data.
    Parameters:
      String id - The ID of the person to update; only the special VIEWER ID is currently allowed.
      String key - The name of the key
      String value - The value
    Returns:
      Object A request object

send

send(opt_callback)
    Sends a data request to the server in order to get a data response. Although the server may optimize these requests, they will always be executed as though they were serial.
    Parameters:
      Function opt_callback - The function to call with the data response generated by the server

Documentation generated by JsDoc Toolkit 1.3.3