Exemplo n.º 1
0
    echo htmlspecialchars((string) $Listing->Title);
    ?>
</option>
            <?php 
}
?>
      </select>
      
      <p><strong>Note:</strong></p>
      <textarea name="Note[Note]"></textarea>
      <input type="submit" value="Submit" />
    </form>
    <h1>Your Existing Watchlist Notes</h1>
    <dl>
    <?php 
$Watchlist = trademe()->get('MyTradeMe/Watchlist');
foreach ($Watchlist->List->WatchlistItem as $Item) {
    if (!isset($Item->Note) || !strlen((string) $Item->Note)) {
        continue;
    }
    ?>
        <dt><?php 
    echo htmlspecialchars($Item->Title);
    ?>
</dt>
        <dd>
          <p><?php 
    echo htmlspecialchars($Item->Note);
    ?>
</p>
          [<a href="save_note.php?Delete[NoteId]=<?php 
Exemplo n.º 2
0
<?php

/** This is the callback, what we do is take 'oauth_verifier' from our $_REQUEST, and pass this back
 *  to trademe who will give us another token, an access token, which we can use to make actual useful
 *  requests in future.
 */
require_once 'include/init.php';
// We must use the same request token we obtained in connect.php
$RequestToken = retrieve_token('request');
trademe()->set_token($RequestToken);
// And now we get the access token using the verifier
$AccessToken = trademe()->get_access_token($_REQUEST['oauth_verifier']);
// Which we save, because we now can use this to make any future requests
//  until the access token expires, which I believe for TradeMe is a year (?)
store_token($AccessToken);
include '_header.php';
?>

      <h1 class="css-content-legend">We are (in theory) connected To TradeMe</h1>      
         
      <p>
        You don't have to reauthorise unless you lose the Access Token or it expires. So store the Access Token in a database, config file, or whatever so your users don't have to reauthorise all the time.  
      </p>     
      
      <p>This example only stores it in the $_SESSION, that's probably not very useful to you in production but it suffices for the examples :-)</p>
      
      <p>
        Now you can <a href="index.php">try it out with some simple demos</a>.
      </p>
      
    
Exemplo n.º 3
0
              </tr>
            </table>              
          </td>
        </tr>
        
        
        <!-- Attributes -->
        <tr>
          <th>Attributes</th>
          <td>These are attributes specific to the category, please see the code at line <?php 
echo __LINE__;
?>
 for how this list is generated.</td>
        </tr>
        <?php 
$Attributes = trademe()->get('Categories/0002-0357-0507-/Attributes');
$x = -1;
foreach ($Attributes->Attribute as $Attribute) {
    $x++;
    ?>
            <tr>
              <th><?php 
    echo (string) $Attribute->DisplayName;
    ?>
</th>
              <td>
                <input type="hidden"   name="Listing[Attributes][Attribute][<?php 
    echo $x;
    ?>
][Name]" value="<?php 
    echo (string) $Attribute->Name;
Exemplo n.º 4
0
 */
require_once 'include/init.php';
// We set the access token which we stored in callback.php (at some earlier time)
$AccessToken = retrieve_token('access');
trademe()->set_token($AccessToken);
if (isset($_REQUEST['Endpoint'])) {
    // And then simply call the "endpoint" at trademe.
    // $Response = trademe()->SaveNote($_REQUEST['Note']['ListingID'], $_REQUEST['Note']['Note']);
    $Params = array();
    if (trim(@$_REQUEST['Params'])) {
        foreach (preg_split('/\\r?\\n/', trim($_REQUEST['Params'])) as $P) {
            list($k, $v) = explode('=', $P, 2);
            $Params[$k] = $v;
        }
    }
    $Response = trademe()->get($_REQUEST['Endpoint'], $Params);
    if (!@$_REQUEST['Raw']) {
        include_once '_header.php';
        // We can check the response is OK
        if ($Response->is_ok()) {
            echo "<h1>Success!</h1>";
            echo "<pre>" . htmlspecialchars($Response->asIndentedXML()) . "</pre>";
        } else {
            echo "<h1>Failure</h1>";
            echo "<p>Error response from TradeMe follows...</p>";
            echo "<pre>" . htmlspecialchars($Response->error_message()) . "</pre>";
        }
    } else {
        header('Content-type: text/xml');
        echo $Response;
        exit;
        echo "<h1>Success</h1>";
        echo "<p>TradeMe returned the following XML.</p>";
        echo "<pre>" . htmlspecialchars($Response->asIndentedXML()) . "</pre>";
        echo "<p>You will see it includes a &quot;DeliveryAddressId&quot;, perhaps you want to use that your application, this is how you would get it.</p>";
        echo "<pre>" . htmlspecialchars('$TheDeliveryAddressId = (int) $Response->DeliveryAddressId;') . "</pre>";
        echo "<p>The cast is because we are talking to an SimpleXMLElement there, to be safe, always cast to what you want (or at least expect).</p>";
    } else {
        // If an error did happen (is_ok() is false) then error_message() will give
        // you the error message in the trademe response, or something like that.
        echo "<h1>Failure</h1>";
        echo "<p>Error response from TradeMe follows...</p>";
        echo "<pre>" . htmlspecialchars($Response->error_message()) . "</pre>";
        // echo $Response->error_message();
    }
}
$Addresses = trademe()->get('MyTradeMe/DeliveryAddresses');
?>
    <h1>Add A Delivery Address</h1>    
    <p>The XML result from the API will be displayed, click back a couple of times to get o the index page when you've satisfied your curiosity.</p>
    <form method="post">
      <table class="css-form-table">
        <tbody>
          <tr><th>Name</th><td><input type="text" name="Address[Name]" /></td></tr>
          <tr><th>Address 1</th><td><input type="text" name="Address[Address1]" /></td></tr>
          <tr><th>Address 2</th><td><input type="text" name="Address[Address2]" /></td></tr>
          <tr><th>Suburb</th><td><input type="text" name="Address[Suburb]" /></td></tr>
          <tr><th>City</th><td><input type="text" name="Address[City]" /></td></tr>
          <tr><th>Post Code</th><td><input type="text" name="Address[Postcode]" /></td></tr>
          <tr><th>Country</th><td><input type="text" name="Address[Country]" /></td></tr>
        </tbody>
      </table>
Exemplo n.º 6
0
<?php

/** This is the connector, your user would use this page when they are connecting your application (/website)
 *  to TradeMe, once they have "connected", they don't need to do it again until that "connection" expires
 *  (which is 12 months I think?), or of course, if you forget the "Access Token"!
 */
require_once 'include/init.php';
// This is where the work really starts, if we have been asked to (re)authorise by the user,
if (isset($_REQUEST['Reauthorise'])) {
    // We get a request token, by providing oauth with OUR url which will handle the "verifier callback"
    //   NOTE: in oauth, "callback" means "TradeMe redirects the user to this url", not a server->server request
    $RequestToken = trademe()->get_request_token();
    // We need to get access to this later, so store it however you want to
    store_token($RequestToken);
    // Now we get a URL from oauth to where we need to redirect the user
    $RedirectURL = trademe()->get_authorize_url();
    // And we send them there, and stop processing
    header('location: ' . $RedirectURL);
    exit;
}
include '_header.php';
?>
      <h1 class="css-content-legend">Connect To TradeMe</h1>    
      <p>In order to connect to your TradeMe account you must complete the authorisation process, simply click on the link below and you will be redirected to TradeMe to authorise access to your account.</p>
          
      <p><a href="connect.php?Reauthorise=1">Begin Authorisation</a></p>
<?php 
include '_footer.php';
Exemplo n.º 7
0
<?php

/** This is an example of using the Access Token to get the user's watchlist, it's about
 *  the simplest example you can possibly have.
 */
require_once 'include/init.php';
// We set the access token which we stored in callback.php (at some earlier time)
$AccessToken = retrieve_token('access');
trademe()->set_token($AccessToken);
// And then simply call the "endpoint" at trademe.
$Response = trademe()->get('MyTradeMe/Watchlist/All', array('page' => 1, 'rows' => 1));
// We can check the response is OK
if ($Response->is_ok()) {
    // Assuming the request worked, you should be able to access the data from it like this...
    //  --- NB: TotalCount will typically be a SimpleXMLElement, so need to have that (int) cast!
    $TotalItemsInWatchlist = (int) $Response->TotalCount;
    // The response object __tostring() returns the body of the response, in this case, raw XML
    // we will just print it out for something to show.
    header('Content-type: text/xml');
    echo $Response;
    // Advanced Note (perhaps for troubleshooting!)
    // -----------------------------------------------------------------------
    // Referencing an OBJECT PROPERTY on the Response automatically performs this
    //  behind the scenes (for example getting the TotalCount property).
    //
    //     $Response->data()->TotalCount;
    //
    // which is an automatically detected switch between either
    //
    // 1.  $Response->xml()->TotalCount;
    // 2.  $Response->json()->TotalCount;
Exemplo n.º 8
0
    }
}
?>
  <h1>Upload a Photo</h1>
  <p>This form will upload a photo to your My Photos at TradeMe.</p>
  <form enctype="multipart/form-data" method="post">
    <input type="file" name="File" /><input type="submit" value="Upload" />
  </form>
  <h1>Your Photos</h1>
  <ul>
  <?php 
$Photos = trademe()->get('Photos');
foreach ($Photos->List->MemberPhoto as $Photo) {
    preg_match('/([1-9]?[0-9])$/', (string) $Photo, $M);
    $Thumb = trademe()->get_thumbnail_url($Photo);
    $Full = trademe()->get_photo_url($Photo);
    ?>
      <li>
        <img src="<?php 
    echo htmlspecialchars($Thumb);
    ?>
" />
        [<a href="upload_photo.php?Delete=<?php 
    echo $Photo->Id;
    ?>
">Delete</a>]
      </li>
      <?php 
}
?>
  
Exemplo n.º 9
0
              <option>OneHour</option>
              <option>TwelveHours</option>
              <option>TwentyFourHours</option>              
            </select>
          </td></tr>          
        </tbody>
      </table>
      <input type="submit" value="Submit" />
    </form>
    
    <h2>Your existing watchlist...</h2>
    <ul>
    <?php 
$Watchlist = trademe()->get('MyTradeMe/Watchlist/All');
foreach ($Watchlist->List->WatchlistItem as $Item) {
    $ListingURL = trademe()->get_listing_url($Item);
    ?>
        <li>
          <a href="<?php 
    echo $ListingURL;
    ?>
"><?php 
    echo $Item->Title;
    ?>
</a> 
            [<a href="save_to_watchlist.php?Delete=<?php 
    echo $Item->ListingId;
    ?>
">Delete</a>]
        </li>
        <?php