-
-
Save datapolitical/3718319 to your computer and use it in GitHub Desktop.
Sample summary gist for PHP on Mashape
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Step 1 - Requre the client library | |
require_once("Bitly.php"); | |
//Step 2 - Instantiate a new client object | |
$bitly = new Bitly("MY_PUBLIC_KEY", "MY_PRIVATE_KEY", "MY_API_KEY", "MY_LOGIN"); | |
//Step 3 - Return a MashapeResponse object by calling a method | |
$response = $bitly->getShortenedUrl("http://mashape.com/docs/consume/php"); | |
//Step 4- Consume the data in a MashapeResponse object | |
echo $response->statusCode; // should be "200" | |
echo $response->headers; // A string showing the headers of the response | |
//Parsed response data is is inside of a property called body | |
echo $response->body->shortenedUrl; | |
if ($response->statusCode == "200") { | |
// $response->body will be a stdClass representing the parsed response | |
echo "Shortened URL: " . $response->body->shortenedUrl; | |
} else { | |
// $response->rawBody will be a string representing the unparsed response | |
echo "Problem with request. Response: " . $response->rawBody; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment