Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for OEmbed and added some debugging info #18

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Instagram/Collection/CollectionAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ abstract class CollectionAbstract implements \IteratorAggregate, \ArrayAccess, \
*/
protected $position;

public $raw_data;

/**
* Constructor
*
Expand All @@ -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 ) {
Expand Down
3 changes: 3 additions & 0 deletions Instagram/Core/BaseObjectAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public function getId() {
return $this->data->id;
}

public $raw_data;

/**
* Get the API ID
*
Expand All @@ -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;
}
Expand Down
18 changes: 17 additions & 1 deletion Instagram/Core/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions Instagram/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
11 changes: 9 additions & 2 deletions Instagram/Net/ApiResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -148,4 +155,4 @@ public function __toString() {
return json_encode( $this->response );
}

}
}
2 changes: 1 addition & 1 deletion Instagram/Net/CurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
27 changes: 27 additions & 0 deletions Instagram/OEmbed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* Instagram PHP
* @author Galen Grover <[email protected]>
* @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 {

}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;