diff --git a/Instagram/Collection/CollectionAbstract.php b/Instagram/Collection/CollectionAbstract.php index ae6d983..c12d9c9 100644 --- a/Instagram/Collection/CollectionAbstract.php +++ b/Instagram/Collection/CollectionAbstract.php @@ -39,6 +39,8 @@ abstract class CollectionAbstract implements \IteratorAggregate, \ArrayAccess, \ */ protected $position; + public $raw_data; + /** * Constructor * @@ -50,6 +52,7 @@ abstract class CollectionAbstract implements \IteratorAggregate, \ArrayAccess, \ */ public function __construct( $raw_data = null, \Instagram\Core\Proxy $proxy = null ) { if ( $raw_data ) { + $this->raw_data = $raw_data; $this->setData( $raw_data ); } if ( $proxy ) { diff --git a/Instagram/Core/BaseObjectAbstract.php b/Instagram/Core/BaseObjectAbstract.php index 8d589e8..aee7741 100644 --- a/Instagram/Core/BaseObjectAbstract.php +++ b/Instagram/Core/BaseObjectAbstract.php @@ -41,6 +41,8 @@ public function getId() { return $this->data->id; } + public $raw_data; + /** * Get the API ID * @@ -63,6 +65,7 @@ public function getApiId() { * @access public */ public function __construct( $data, \Instagram\Core\Proxy $proxy = null ) { + $this->raw_data = $data; $this->setData( $data ); $this->proxy = $proxy; } diff --git a/Instagram/Core/Proxy.php b/Instagram/Core/Proxy.php index 8efbc35..4df9909 100644 --- a/Instagram/Core/Proxy.php +++ b/Instagram/Core/Proxy.php @@ -49,6 +49,7 @@ class Proxy { * @access protected */ protected $api_url = 'https://api.instagram.com/v1'; + protected $api_oembed_url = 'http://api.instagram.com/oembed'; /** * Constructor @@ -272,6 +273,21 @@ public function getMedia( $id ) { return $response->getData(); } + /** + * Get oembed + * + * @param string $url The URL of the instagram Post + * @return StdClass Returns the media data + * @access public + */ + public function getOEmbed( $url ) { + $response = $this->apiCall( + 'get', + sprintf( '%s/oembed/?url=%s', $this->api_oembed_url, $url ) + ); + return $response->getData(); + } + /** * Get tag * @@ -549,7 +565,7 @@ private function apiCall( $method, $url, array $params = null, $throw_exception throw new \Instagram\Core\ApiAuthException( $response->getErrorMessage(), $response->getErrorCode(), $response->getErrorType() ); } else { - throw new \Instagram\Core\ApiException( $response->getErrorMessage(), $response->getErrorCode(), $response->getErrorType() ); + throw new \Instagram\Core\ApiException( __FILE__ . ' : ' . $url . ' - ' . $response->getErrorMessage(), $response->getErrorCode(), $response->getErrorType() ); } } else { diff --git a/Instagram/Instagram.php b/Instagram/Instagram.php index 82d745a..ce22b48 100644 --- a/Instagram/Instagram.php +++ b/Instagram/Instagram.php @@ -149,6 +149,18 @@ public function getTag( $tag ) { return $tag; } + /** + * Get OEmbed + * + * @param string $url The URL of the instagram Post + * @return \Instagram\Media + * @access public + */ + public function getOEmbed( $url ) { + $oembed = new OEmbed( $this->proxy->getOEmbed( $url ), $this->proxy ); + return $oembed; + } + /** * Get location * diff --git a/Instagram/Net/ApiResponse.php b/Instagram/Net/ApiResponse.php index d23eb68..c302ba7 100644 --- a/Instagram/Net/ApiResponse.php +++ b/Instagram/Net/ApiResponse.php @@ -75,7 +75,14 @@ public function isValidApiResponse() { * @access public */ public function getData() { - return isset( $this->response->data ) ? $this->response->data : null; + if (isset( $this->response->data )) + { + return $this->response->data; + }elseif (isset($this->response->media_id)) + { + return $this->response; + } + return null; } /** @@ -148,4 +155,4 @@ public function __toString() { return json_encode( $this->response ); } -} \ No newline at end of file +} diff --git a/Instagram/Net/CurlClient.php b/Instagram/Net/CurlClient.php index 90bf7b8..ee82777 100644 --- a/Instagram/Net/CurlClient.php +++ b/Instagram/Net/CurlClient.php @@ -112,7 +112,7 @@ protected function fetch() { $raw_response = curl_exec( $this->curl ); $error = curl_error( $this->curl ); if ( $error ) { - throw new \Instagram\Core\ApiException( $error, 666, 'CurlError' ); + throw new \Instagram\Core\ApiException( 'CurlClient::fetch() ' . __FILE__ . ' : ' . $error, 666, 'CurlError' ); } return $raw_response; } diff --git a/Instagram/OEmbed.php b/Instagram/OEmbed.php new file mode 100644 index 0000000..c3d58af --- /dev/null +++ b/Instagram/OEmbed.php @@ -0,0 +1,27 @@ + +* @license http://opensource.org/licenses/mit-license.php The MIT License +*/ + +namespace Instagram; + +use \Instagram\Comment; +use \Instagram\User; +use \Instagram\Location; +use \Instagram\Collection\CommentCollection; +use \Instagram\Collection\TagCollection; +use \Instagram\Collection\UserCollection; + +/** + * Media class + * + * @see \Instagram\Instagram->getLocation() + * {@link https://github.com/galen/PHP-Instagram-API/blob/master/Examples/media.php} + * {@link http://galengrover.com/projects/instagram/?example=media.php} + */ +class OEmbed extends \Instagram\Core\BaseObjectAbstract { + +} \ No newline at end of file diff --git a/README.md b/README.md index bdbec1f..48cb66e 100644 --- a/README.md +++ b/README.md @@ -161,3 +161,11 @@ You can search for locations, media, tags, and users. $media = $instagram->searchMedia( $lat, $lng ); $tags = $instagram->searchTags( 'tag' ); $users = $instagram->searchUsers( 'username' ); + +##OEmbed + +Get information about a shared link (http://instagram.com/developer/embedding/#oembed) + + $instagram_post = "http://instagr.am/p/aBcDeFg123/" + $oembed = $instagram->getOEmbed( $instagram_post_url ); + echo $oembed->media_id;