PHP code example of jublonet / shapecode-php
1. Go to this page and download the library: Download jublonet/shapecode-php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jublonet / shapecode-php example snippets
Shapecode::setConsumerKey('YOURKEY', 'YOURSECRET'); // static, see 'Using multiple Shapecode instances'
$sc = Shapecode::getInstance();
$sc->setToken('YOURTOKEN', 'YOURTOKENSECRET');
session_start();
if (! isset($_SESSION['oauth_token'])) {
// get the request token
$reply = $sc->oauth1_requestToken(array(
'oauth_callback' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
));
// store the token
$_SESSION['oauth_token'] = $reply->oauth_token;
$_SESSION['oauth_token_secret'] = $reply->oauth_token_secret;
$_SESSION['oauth_verify'] = true;
// redirect to auth website
header('Location: ' . $reply->authentication_url);
die();
} elseif (isset($_GET['oauth_verifier']) && isset($_SESSION['oauth_verify'])) {
// verify the token
$sc->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
unset($_SESSION['oauth_verify']);
// get the access token
$reply = $sc->oauth1_accessToken(array(
'oauth_verifier' => $_GET['oauth_verifier']
));
// store the token (which is different from the request token!)
$_SESSION['oauth_token'] = $reply->oauth_token;
$_SESSION['oauth_token_secret'] = $reply->oauth_token_secret;
// send to same URL, without oauth GET parameters
header('Location: ' . basename(__FILE__));
die();
}
// assign access token on each page load
$sc->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
$sc->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']); // see above
$reply = (array) $sc->api();
print_r($reply);
$reply = $sc->orders_cart('modelId=480903');
$params = array(
'modelId' => '480903',
'materialId' => 61,
'quantity' => 3
);
$reply = $sc->orders_cart($params);
$params = array(
'file' => 'in-some-folder/there-is/the-model.stl',
'fileName' => 'the-model.stl',
'hasRightsToModel' => 1,
'acceptTermsAndConditions' => 1,
'title' => 'My great model',
'description' => 'Lorem ipsum dolor sit amet',
'isPublic' => 1,
'isForSale' => 1,
'isDownloadable' => 0,
'tags' => array(
'ideas',
'miniatures',
'stuff'
)
);
$reply = $sc->models($params); //
$sc->setReturnFormat(SHAPECODE_RETURNFORMAT_ARRAY);
$sc->setReturnFormat(SHAPECODE_RETURNFORMAT_JSON);
$sc = Shapecode::getInstance();
$sc1 = new Shapecode;
$sc2 = new Shapecode;
$page = 1;
$result1 = $sc->models();
$page++;
$result2 = $sc->models("page=$page");
$sc->setConnectionTimeout(2000);
$sc->setTimeout(5000);
$sc->setUseCurl(false);