A PHP based example on how to generate a usable API Key based on a successful authorization


  1. <pre>
  2. <?php
  3. /* In this demonstration we will be demonstrating how to authorize your application to use a Panacea Mobile user's account */

  4. require_once("../../php/panacea_api.php"); // Let's just include the Panacea Api class (downloadable at http://www.panaceamobile.com/developers/sample-code/php/)
  5. $api = new PanaceaApi();

  6. if(!empty($_GET['request_key'])) {
  7. /* Great we have a request key, so let's get our authorization token! */

  8. $token = $api->user_get_api_key($_GET['request_key']);

  9. if($api->ok($token)) {
  10. /* We have created an API Key, wahoo! */

  11. $username = $token['details']['username'];
  12. $key = $token['details']['key'];

  13. /* Let's use it */
  14. $api->setUsername($username);
  15. $api->setPassword($key);

  16. $balance = $api->user_get_balance();

  17. if($api->ok($balance)) {
  18. echo "Your balance is {$balance['details']}\n";
  19. }
  20. } else {
  21. echo "Not authorized\n";
  22. }
  23. } else {
  24. echo "Not authorized\n";
  25. }