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);
     $userid = $ms->getCurrentUserId();
     $this->assertTrue($userid != 0);
 }
 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);
     $userId = $ms->getCurrentUserId();
     $notification = $ms->sendNotification($userId, $userId, array('content' => 'this is  content'), 'http://opensocial.myspace.com/roa/09/mediaitemcomments/');
     $this->assertTrue($notification->statusLink != NULL, "Send Notification Failed");
 }
function run()
{
    $consumer = getConsumer();
    // Complete the authentication process using the server's
    // response.
    $return_to = getReturnTo();
    $response = $consumer->complete($return_to);
    // Check the response status.
    if ($response->status == Auth_OpenID_CANCEL) {
        // This means the authentication was cancelled.
        $msg = 'Verification cancelled.';
    } else {
        if ($response->status == Auth_OpenID_FAILURE) {
            // Authentication failed; display the error message.d
            $msg = "OpenID authentication failed: " . $response->message;
        } else {
            if ($response->status == Auth_OpenID_SUCCESS) {
                // This means the authentication succeeded; extract the
                // identity URL and Simple Registration data (if it was
                // returned).
                $openid = $response->getDisplayIdentifier();
                $esc_identity = escape($openid);
                $success = sprintf('You have successfully verified ' . '<a href="%s">%s</a> as your identity.<br><br>Here\'s your MySpace profile data fetched using the MySpace REST APIs', $esc_identity, $esc_identity);
                if ($response->endpoint->canonicalID) {
                    $escaped_canonicalID = escape($response->endpoint->canonicalID);
                    $success .= '  (XRI CanonicalID: ' . $escaped_canonicalID . ') ';
                }
                $oauth_resp = Auth_OpenID_OAuthResponse::fromSuccessResponse($response);
                $authorized_request_token = $oauth_resp->authorized_request_token;
                //1.0A OAuth Spec, we will need this to get an access token
                $authorized_verifier = $oauth_resp->authorized_verifier;
                if ($authorized_request_token) {
                    $ms = new MySpace(CONSUMER_KEY, CONSUMER_SECRET, $authorized_request_token->key, $authorized_request_token->secret, $authorized_verifier);
                    $access_token = $ms->getAccessToken();
                    $ms = new MySpace(CONSUMER_KEY, CONSUMER_SECRET, $access_token->key, $access_token->secret);
                    $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);
                    $friends_data = $ms->getFriends($userid);
                    $ms->updateStatus($userid, 'testing sdk');
                    // Access $profile_data and $friend_data inside of index.php (via the include below)
                    // to display the profile/friends data
                }
            }
        }
    }
    include 'index.php';
}
 public function test_pass()
 {
     $ms_key = CONSUMER_KEY;
     $ms_secret = CONSUMER_SECRET;
     $token = OAUTH_TOKEN;
     $secret = OAUTH_SECRET;
     $appId = APP_ID;
     $ms = new MySpace($ms_key, $ms_secret, $token, $secret);
     $userid = $ms->getCurrentUserId();
     $getApp = $ms->getAppData("@me", $appId);
     $this->assertTrue(count($getApp) >= 0, "Get App Data Failed");
     $addApp = $ms->addAppData("@me", $appId, 'test', 'values23');
     $this->assertEqual($addApp->statusLink != NULL, "Add App Data Failed");
     $delApp = $ms->clearAppData("@me", $appId, 'test');
     $this->assertEqual($delApp == 1, "Delete App Data 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);
     $userid = $ms->getCurrentUserId();
     $fields = $ms->getActivitiesSupportedFields();
     $this->assertTrue(count($fields) > 0);
     $verbs = $ms->getActivitiesSupportedVerbs();
     $this->assertTrue(count($verbs) > 0);
     $types = $ms->getActivitiesSupportedTypes();
     $this->assertTrue(count($types) > 0);
     $activites = $ms->getActivities($userid);
     $this->assertTrue(count($activities) >= 0);
     $friendActivities = $ms->getFriendsActivities($userid);
     $this->assertTrue(count($friendActivities) >= 0);
 }
Beispiel #6
0
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 
            }
        }
    }
}
 function connect()
 {
     $ms_key = CONSUMER_KEY;
     //we get this from config.MySpace.php
     $ms_secret = CONSUMER_SECRET;
     if (!empty($this->params['url']['f'])) {
         if ($this->params['url']['f'] == 'start') {
             // get a request token + secret from MySpace and redirect to the authorization page
             $ms = new MySpace($ms_key, $ms_secret);
             $host = $_SERVER['HTTP_HOST'] . $this->base;
             $tok = $ms->getRequestToken("http://{$host}/mss/connect/?f=callback");
             if (!isset($tok['oauth_token']) || !is_string($tok['oauth_token']) || !isset($tok['oauth_token_secret']) || !is_string($tok['oauth_token_secret'])) {
                 $this->Session->setFlash('Invalid response.');
                 $this->redirect('/band/manage/');
                 exit;
             }
             $this->Session->write('auth_state', 'start');
             $this->Session->write('request_token', $tok['oauth_token']);
             $this->Session->write('request_secret', $tok['oauth_token_secret']);
             $this->Session->write('callback_confirmed', $tok['oauth_callback_confirmed']);
             header("Location: " . $ms->getAuthorizeURL($tok['oauth_token']));
             exit;
         } else {
             if (@$_GET['f'] == 'callback') {
                 // the user has authorized us at MySpace, so now we can pick up our access token + secret
                 if ($this->Session->check('auth_state')) {
                     if ($this->Session->read('auth_state') != 'start') {
                         $this->Session->setFlash('Invalid call.');
                         $this->redirect('/band/manage/');
                         exit;
                     }
                 }
                 // if($this->Session->check('auth_state'))
                 // the user has authorized us at MySpace, so now we can pick up our access token + secret
                 if (!empty($this->params['url']['oauth_problem'])) {
                     if ($this->params['url']['oauth_problem'] == 'user_refused') {
                         $this->redirect('/band/manage/');
                         exit;
                     } else {
                         $this->Session->setFlash('Authorization problem.');
                         $this->redirect('/band/manage/');
                         exit;
                     }
                 }
                 // if($this->Session->check('auth_state'))
                 /*
                 				Get Band Id from Session or Cookie
                 */
                 if ($this->Session->check('band_id')) {
                     $band_id = $this->Session->read('band_id');
                 } elseif ($this->Cookie->valid('bandid')) {
                     $band = $this->Cookie->read('bandid');
                     $band_id = $band['bandid'];
                     // band_id value get from cookie
                 } else {
                     $this->Session->setFlash('Please select a band.');
                     $this->redirect('/band/index/');
                     exit;
                 }
                 $oauth_verifier = $this->params['url']['oauth_verifier'];
                 if (!isset($oauth_verifier)) {
                     $this->Session->setFlash('Invalid response.');
                     $this->redirect('/band/manage/');
                     exit;
                 }
                 $ms = new MySpace($ms_key, $ms_secret, $this->Session->read('request_token'), $this->Session->read('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));
                     $this->Session->setFlash('Invalid response.');
                     $this->redirect('/band/manage/');
                     exit;
                 }
                 $ms = new MySpace($ms_key, $ms_secret, $tok->key, $tok->secret);
                 $webUri = $ms->getCurrentUserId();
                 // get user id from webUri
                 $user_id = substr($webUri, strrpos($webUri, "/") + 1, strlen($webUri));
                 $result = $this->Msslogin->find(array('user_id' => $user_id, 'band_id' => $band_id));
                 if ($result) {
                     $result['Msslogin']['access_token'] = $tok->key;
                     $result['Msslogin']['access_secret'] = $tok->secret;
                     $result['Msslogin']['oauth_token'] = $this->Session->read('request_token');
                     $result['Msslogin']['oauth_token_secret'] = $this->Session->read('request_secret');
                     $result['Msslogin']['link'] = '1';
                     $this->Msslogin->save($result);
                     $this->Session->setFlash('MySpace update status permission allowed.');
                     $band = $this->Cookie->read('flag');
                     // myspace called from wizard or setting manage
                     $flag = $band["flag"];
                     if ($flag == 'b') {
                         $this->redirect('/band/myspace/');
                     } else {
                         $this->redirect('/band/manage/');
                     }
                     exit;
                 } else {
                     // return to band manager or band wizard page
                     $this->addprofile($user_id, $tok->key, $tok->secret, $band_id);
                 }
             }
         }
     } else {
         $this->Session->setFlash('Invalid response.');
         $this->redirect('/band/manage/');
         exit;
     }
     $this->Session->setFlash('Invalid response.');
     $this->redirect('/band/manage/');
     exit;
 }
function run()
{
    $consumer = getConsumer();
    // Complete the authentication process using the server's
    // response.
    $return_to = getReturnTo();
    $response = $consumer->complete($return_to);
    // Check the response status.
    if ($response->status == Auth_OpenID_CANCEL) {
        // This means the authentication was cancelled.
        $msg = 'Verification cancelled.';
    } else {
        if ($response->status == Auth_OpenID_FAILURE) {
            // Authentication failed; display the error message.d
            $msg = "OpenID authentication failed: " . $response->message;
        } else {
            if ($response->status == Auth_OpenID_SUCCESS) {
                // This means the authentication succeeded; extract the
                // identity URL and Simple Registration data (if it was
                // returned).
                $openid = $response->getDisplayIdentifier();
                $esc_identity = escape($openid);
                $success = sprintf('You have successfully verified ' . '<a href="%s">%s</a> as your identity.<br><br>Here\'s your MySpace profile data fetched using the MySpace REST APIs', $esc_identity, $esc_identity);
                if ($response->endpoint->canonicalID) {
                    $escaped_canonicalID = escape($response->endpoint->canonicalID);
                    $success .= '  (XRI CanonicalID: ' . $escaped_canonicalID . ') ';
                }
                $oauth_resp = Auth_OpenID_OAuthResponse::fromSuccessResponse($response);
                $authorized_request_token = $oauth_resp->authorized_request_token;
                $authorized_verifier = $oauth_resp->authorized_verifier;
                if ($authorized_request_token) {
                    $ms = new MySpace(CONSUMER_KEY, CONSUMER_SECRET, $authorized_request_token->key, $authorized_request_token->secret, $authorized_verifier);
                    $access_token = $ms->getAccessToken();
                    $ms = new MySpace(CONSUMER_KEY, CONSUMER_SECRET, $access_token->key, $access_token->secret);
                    $userid = $ms->getCurrentUserId();
                    $_SESSION['userID'] = $userid;
                    $_SESSION['access_token_key'] = $access_token->key;
                    $_SESSION['access_token_secret'] = $access_token->secret;
                    // Use the userID (fetched in the previous step) to get user's profile, friends and other info
                    $profile_data = $ms->getProfile($userid);
                    $friends_data = $ms->getFriends($userid);
                    // Access $profile_data and $friend_data inside of index.php (via the include below)
                    // to display the profile/friends data
                }
            }
        }
    }
    ?>
    <html>
  <head><title>MySpaceID Hybrid Example</title></head>

  <link rel="stylesheet" type="text/css" href="static/base.css">

  <!-- YUI Combo CSS + JS files: -->
  <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/combo?2.6.0/build/tabview/assets/skins/sam/tabview.css">
  <script type="text/javascript" src="http://yui.yahooapis.com/combo?2.6.0/build/yahoo-dom-event/yahoo-dom-event.js&2.6.0/build/imageloader/imageloader-min.js&2.6.0/build/element/element-beta-min.js&2.6.0/build/tabview/tabview-min.js"></script>

  <body class="yui-skin-sam">

<script>
function closeWin() {
//  alert("closeWin() called");
//  alert(opener);

//window.opener.location.href = "profile.php";
//  window.opener.location.reload(true);
var rand = Math.random();

alert(rand);

  window.opener.sayhi(rand);
  self.close();
}
</script>





    <h1>Finishing Log In</h1>



    <br>

    <?php 
    if (isset($msg)) {
        print "<div class=\"alert\">{$msg}</div>";
    }
    ?>
    <?php 
    if (isset($error)) {
        print "<div class=\"error\">{$error}</div>";
    }
    ?>
    <?php 
    if (isset($success)) {
        print "<div class=\"success\">{$success}</div>";
    }
    ?>



<script>closeWin();</script>
  </body>
</html>
<?php 
}