A PHP based example on how to generate an API Key request token and redirect the user


  1. <pre>
  2. <?php
  3. /* In this demonstration we will be demonstrating how to authorize your application to use a TotalSend 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. /* First, we need to contact TotalSend servers in order to let them know that we will be sending a user to them for authorization */

  7. $application_name = "My Application";

  8. /**
  9. * If needed, after the application has been authorized, TotalSend can redirect the user to a success page or failed page on your server
  10. *
  11. * If these values are not specified, the user will just be given the option to close the window (for use on Mobile phones for example)
  12. *
  13. * An HTTP GET variable 'request_key' will be appended to this URL for tracking purposes
  14. *
  15. */

  16. $return_url = "http://smsapi.totalsend.com/examples/demos/api_key_creation/step2.php";
  17. $icon_url = null; /* A URL containing an icon to make your application easily identifiable to the user (optional) */

  18. $request_key = $api->user_authorize_application($application_name, $icon_url, $return_url);

  19. if($api->ok($request_key)) {
  20. /* We have a request key to use */

  21. /* We are going to store the request key in a session for simplicity */

  22. $_SESSION['api_request_key'] = $request_key['details']['request_key'];

  23. /* Now we must present the user with the authorization page for TotalSend to allow this user to authorize our application */

  24. echo "<a href='".htmlspecialchars($request_key['details']['authorize_url'])."'>authorize now with TotalSend</a>";
  25. exit(0);
  26. }

  27. echo "Unable to generate request key";




  28. ?>
  29. </pre>