public function test_pass() { $ms_key = CONSUMER_KEY; $ms_secret = CONSUMER_SECRET; $token = OAUTH_TOKEN; $secret = OAUTH_SECRET; $ms = new MySpace($ms_key, $ms_secret, $token, $secret); $mediaFields = $ms->getMediaItemSupportedFields(); $this->assertTrue(count($mediaFields) != 0); $albums = $ms->getAlbums("@me"); $this->assertTrue(count($albums) >= 0); if (count($albums) >= 0) { $getMediaItem = $ms->getMediaItems("@me", $albums->entry[0]->album->id); $this->assertTrue(count($getMediaItems) >= 0); if (count($getMediaItem) >= 0) { $itemById = $ms->getMediaItemById("@me", $albums->entry[0]->album->id, $getMediaItem->entry[0]->mediaItem->id); $this->assertEqual($getMediaItem->entry[0]->mediaItem->id, $itemById->mediaItem->id, "Get Media Item By Id Failed"); } } $videoCategories = $ms->getVideosCategories("@me"); $this->assertTrue(count($videoCategories) > 0, "Get Videos Categories Failed"); if (count($videoCategories) >= 0) { $videoCategoriesById = $ms->getVideosCategoriesById("@me", $videoCategories->array[0]->id); $this->assertTrue(count($videoCategoriesById) >= 0, "Get Video Catgegories By Id"); } }
public function test_pass() { $ms_key = CONSUMER_KEY; $ms_secret = CONSUMER_SECRET; $token = OAUTH_TOKEN; $secret = OAUTH_SECRET; $ms = new MySpace($ms_key, $ms_secret, $token, $secret); $albums = $ms->getAlbums("@me"); if (count($albums) >= 0) { $getMediaItem = $ms->getMediaItems("@me", $albums->entry[0]->album->id); if (count($getMediaItem) >= 0) { $comments = $ms->getMediaItemComments("@me", $albums->entry[0]->album->id, $getMediaItem->entry[0]->mediaItem->id); $this->assertTrue(count($comments) >= 0, "Get Media Item Comments Failed"); } } }
public function test_pass() { $ms_key = CONSUMER_KEY; $ms_secret = CONSUMER_SECRET; $token = OAUTH_TOKEN; $secret = OAUTH_SECRET; $ms = new MySpace($ms_key, $ms_secret, $token, $secret); $albumFields = $ms->getAlbumsSupportedFields(); $this->assertTrue(count($albumFields) != 0); $albums = $ms->getAlbums("@me"); $this->assertTrue(count($albums) >= 0); $addAlbum = $ms->addAlbum("@me", "myalbum"); $this->assertTrue($addAlbum->statusLink != NULL); if (count($albums) >= 0) { $updateAlbum = $ms->updateAlbum("@me", $albums->entry[0]->album->id, "myalbum2"); $this->assertTrue($updateAlbum->statusLink != NULL); $album = $ms->getAlbum("@me", $albums->entry[0]->album->id); $this->assertEqual($album->album->id, $albums->entry[0]->album->id); } }
function main() { $ms_key = CONSUMER_KEY; //we get this from config.MySpace.php $ms_secret = CONSUMER_SECRET; ob_start(); //starts output buffering session_start(); if (@$_GET['f'] == 'start') { // get a request token + secret from MySpace and redirect to the authorization page // $ms = new MySpace($ms_key, $ms_secret); $tok = $ms->getRequestToken("http://localhost/~babar/myspace/myspaceid-sdk/trunk/samples/myspaceid-oauth/index.php?f=callback"); /* if (!isset($tok['oauth_token']) || !is_string($tok['oauth_token']) || !isset($tok['oauth_token_secret']) || !is_string($tok['oauth_token_secret'])) { echo "ERROR! MySpace::getRequestToken() returned an invalid response. Giving up."; exit; } */ $_SESSION['auth_state'] = "start"; $_SESSION['request_token'] = $token = $tok['oauth_token']; $_SESSION['request_secret'] = $tok['oauth_token_secret']; $_SESSION['callback_confirmed'] = $tok['oauth_callback_confirmed']; header("Location: " . $ms->getAuthorizeURL($token)); } else { if (@$_GET['f'] == 'callback') { // the user has authorized us at MySpace, so now we can pick up our access token + secret // if (@$_SESSION['auth_state'] != "start") { echo "Out of sequence."; exit; } $oauth_verifier = @$_GET['oauth_verifier']; if (!isset($oauth_verifier)) { echo "ERROR! MySpace::getAccessToken() returned an invalid response. Giving up."; exit; } // if ($_GET['oauth_token'] != $_SESSION['request_token']) { // echo "Token mismatch."; // exit; // } $ms = new MySpace($ms_key, $ms_secret, $_SESSION['request_token'], $_SESSION['request_secret'], true, $oauth_verifier); $tok = $ms->getAccessToken(); if (!is_string($tok->key) || !is_string($tok->secret)) { error_log("Bad token from MySpace::getAccessToken(): " . var_export($tok, TRUE)); echo "ERROR! MySpace::getAccessToken() returned an invalid response. Giving up."; exit; } $_SESSION['access_token'] = $tok->key; $_SESSION['access_secret'] = $tok->secret; $_SESSION['auth_state'] = "done"; header("Location: " . $_SERVER['SCRIPT_NAME']); } else { if (@$_SESSION['auth_state'] == 'done') { // we have our access token + secret, so now we can actually *use* the api // $ms = new MySpace($ms_key, $ms_secret, $_SESSION['access_token'], $_SESSION['access_secret']); // First get the user id. $userid = $ms->getCurrentUserId(); // Use the userID (fetched in the previous step) to get user's profile, friends and other info $profile_data = $ms->getProfile($userid); displayProfileInfo($profile_data); $friends_data = $ms->getFriends($userid); displayFriendsInfo($friends_data); $albums = $ms->getAlbums($userid); $albumid = $albums->albums[0]->id; $albumInfo = $ms->getAlbumInfo($userid, $albumid); $album = $ms->getAlbum($userid, $albumid); $firstPhoto = $ms->getAlbumPhoto($userid, $albumid, $album->photos[0]->id); displayAlbum($albumInfo, $firstPhoto->imageUri); $friendStatus = $ms->getFriendsStatus($userid); displayObject($friendStatus, '$friendStatus'); $indicators = $ms->getIndicators($userid); displayObject($indicators, '$indicators'); $statusHistory = $ms->getStatusHistory($userid); displayObject($statusHistory, '$statusHistory'); //$ms->updateStatus($userid, 'Updating from php sdk'); // Test put and get app data $ms->putAppData($userid, array('location' => 'usa', 'interests' => 'tennis, golf', 'age' => '21')); $appData = $ms->getAppData($userid, 'interests;location'); displayObject($appData, '$appData for interests and location only'); $appData = $ms->getAppData($userid); displayObject($appData, '$appData for all parameters'); // Test clear app data $ms->clearAppData($userid, 'location;age'); sleep(3); $appData = $ms->getAppData($userid); displayObject($appData, '$appData after clearing'); // Test get friends' app data $appData = $ms->getUserFriendsAppData($userid); displayObject($appData, '$appData for friends'); // Test Poco get user $pocoPerson = $ms->getPersonPoco('movies'); displayObject($pocoPerson, '$pocoPerson'); // Test Poco get friends $pocoFriends = $ms->getFriendsPoco(); displayObject($pocoFriends, '$pocoPerson'); } else { // not authenticated yet, so give a link to use to start authentication. ?> <p><a href="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?> ?f=start">Click here to authenticate with MySpace</a></p><?php } } } }