Skip to content

Envato API PHP Code Samples

Here’s some code samples for working with the new Envato API

These will help people migrate as the old API is getting shut down.

Simple verify-purchase through the new API

WordPress oAuth PHP Class Example

This is a simple PHP class for interacting with the Envato API within a WordPress plugin. It uses some of the WordPress functions like wp_remote_get()

Simple usage example:

$envato_api = envato_api_basic::getInstance();
$envato_api->set_client_id('YOUR_CLIENT_ID_HERE');
$envato_api->set_client_secret('YOUR_CLIENT_SECRET_HERE');
$envato_api->set_redirect_url('http://yourwebsite.com/path/to/this/php/script.php');
$code = !empty($_GET['code']) ? $_GET['code'] : false;
if($code && $token = $envato_api->get_authentication($code) && $envato_api_result = $envato_api->api('v1/market/private/user/username.json')){
   // user is logged in with oAuth
   if(!empty($envato_api_result['username'])){
      echo "Welcome ".htmlspecialchars($envato_api_result['username']);
   }else{
      echo "API Error, unable to get username.";
   }
}else{
   $login_url = $envato_api->get_authorization_url();
   echo '<a href="'.esc_url($login_url).'" target="_blank"> Login with Envato </a>';
}

 

 

Drupal oAuth PHP Class Example

This was created by Envato user sowailem.  It uses some special drupal code so probably best to only be used inside a drupal environment. However it’s a great example of a class and can be pulled apart to adapt to other platforms.

 

Published inEnvato

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

© dtbaker.net