示例#1
0
 /**
  * Converts a response into a native data type.
  *
  * @param array $array the raw data
  * @param boolean $strictMode whether to throw spec errors
  * @return osapiPerson
  */
 public static function convertarray($array, $strictMode = true)
 {
     $instance = new osapiMediaItem();
     $defaults = get_class_vars('osapiMediaItem');
     if ($strictMode && sizeof($defaults > sizeof($array))) {
         throw new osapiException("Unexpected fields in mediaItem response" . print_r($array, true));
     }
     foreach ($array as $key => $value) {
         $instance->setField($key, $value);
     }
     return self::trimResponse($instance);
 }
    // supported fields
    $batch->add($osapi->mediaItems->getSupportedFields(), 'supported_fields');
    // Request the mediaItems for album
    $user_params = array('userId' => $userId, 'groupId' => '@self', 'albumId' => 'myspace.com.album.81886', 'count' => 2);
    $batch->add($osapi->mediaItems->get($user_params), 'get_mediaItems');
    // Fetch mediaItem by id
    $user_params = array('userId' => $userId, 'groupId' => '@self', 'fields' => 'albumId,ratings,tags,numcomments', 'albumId' => 'myspace.com.album.81886', 'mediaItemId' => 'myspace.com.mediaItem.image.646364');
    $batch->add($osapi->mediaItems->get($user_params), 'get_mediaItem_for_id');
    // Upload mediaItem
    $data = file_get_contents('images.jpg');
    $user_params = array('userId' => '@me', 'groupId' => '@self', 'albumId' => 'myspace.com.album.81886', 'type' => 'IMAGE', 'mediaItem' => $data, 'contentType' => 'image/jpg');
    // Commented out so everyone doesn't upload a new file on test.
    $batch->add($osapi->mediaItems->uploadContent($user_params), 'upload_mediaItem');
    // Update mediaItem
    $mediaItem = new osapiMediaItem();
    $mediaItem->setField('title', 'title ' . time());
    $mediaItem->setField('caption', 'caption ' . time());
    $mediaItem->setField('description', 'description ' . time());
    $user_params = array('userId' => '@me', 'groupId' => '@self', 'albumId' => 'myspace.com.album.81886', 'mediaItemId' => 'myspace.com.mediaItem.image.646364', 'mediaItem' => $mediaItem);
    $batch->add($osapi->mediaItems->update($user_params), 'update_mediaItem');
    $user_params = array('userId' => $userId, 'groupId' => '@self', 'albumId' => '@videos', 'count' => 2);
    // Request videos (MySpace Specific)
    $batch->add($osapi->mediaItems->get($user_params), 'get_videos');
    // Send the batch request.
    $result = $batch->execute();
    ?>

<h1>mediaItems Example</h1>
<h2>Request:</h2>
<p>This sample fetched the mediaItems for the current user. Then gets mediaItem details for a specific mediaItem. Create a new mediaItem. Then update an existing mediaItem. Lastly we request videos. (MySpace specific)</p>
 * limitations under the License.
 */
// Default to myspace because this is a myspace specific endpoint.
if (!isset($_REQUEST["test"])) {
    $_REQUEST["test"] = 'myspace';
}
require_once "__init__.php";
if ($osapi) {
    if ($strictMode) {
        $osapi->setStrictMode($strictMode);
    }
    // Start a batch so that many requests may be made at once.
    $batch = $osapi->newBatch();
    // Set the status mood MySpace specific.
    $mediaItem = new osapiMediaItem();
    $mediaItem->setField('uri', 'http://api.myspace.com/v1/users/63129100');
    $notification = new osapiNotification();
    $notification->setField('recipientIds', array('63129100'));
    $notification->setField('mediaItems', array($mediaItem));
    $notification->setTemplateParameter('content', 'Hi ${recipient}, here\'s a notification from ${canvasUrl}');
    $params = array('notification' => $notification);
    $batch->add($osapi->notifications->create($params), 'send_notification');
    // Send the batch request.
    $result = $batch->execute();
    ?>

<h1>Notification API Examples</h1>
<h2>Request:</h2>
<p>This sample creates a notification(msypace specific)</p>
<?php 
    require_once 'response_block.php';
 /**
  * Tests osapiMediaItem->setUrl()
  */
 public function testSetUrl()
 {
     $this->osapiMediaItem->setField('url', 'http://example.com');
     $this->assertEquals('http://example.com', $this->osapiMediaItem->getField('url'));
 }