class InstagramOAuth in Drupagram 6
Same name and namespace in other branches
- 7 drupagram.lib.php \InstagramOAuth
A class to provide OAuth enabled access to the Instagram API
Hierarchy
- class \Instagram
- class \InstagramOAuth
Expanded class hierarchy of InstagramOAuth
File
- ./
drupagram.lib.php, line 407 - Classes to implement the full Instagram API
View source
class InstagramOAuth extends Instagram {
protected $client_id;
protected $client_secret;
protected $redirect_uri;
protected $token;
protected $access_token = NULL;
protected $auth_user = array();
/**
* Constructor for the InstagramOAuth class
*/
public function __construct($client_id = NULL, $client_secret = NULL, $redirect_uri = NULL, $access_token = NULL) {
if (empty($client_id) || empty($client_secret)) {
throw new InstagramException(t('You need to configure your Client ID and/or Client Secret keys.'));
}
$this->client_id = $client_id;
$this->client_secret = $client_secret;
if (isset($redirect_uri)) {
$this->redirect_uri = $redirect_uri;
}
if (isset($access_token)) {
$this->access_token = $access_token;
}
}
/**
* Returns the properly formatted authorization url.
*
* @param string $redirect_uri. URI to redirect the user to after authorization
* @param array $scope. Items can be: 'basic', 'comments', 'relationships' and 'likes'
* @param string $response_type. Currently only 'code' is supported
* @return string. Propertly formatted authorization url.
*/
public function get_authorize_url($redirect_uri = NULL, $scope = array(
'basic',
'comments',
'relationships',
'likes',
), $response_type = 'code') {
$url = $this
->create_url('oauth/authorize', '');
$url .= '?client_id=' . $this->client_id;
$url .= '&response_type=' . $response_type;
if (isset($redirect_uri)) {
$url .= '&redirect_uri=' . $redirect_uri;
}
if (isset($scope)) {
$url .= '&scope=' . implode('+', $scope);
}
return $url;
}
/**
* Returns the properly formatted authentication url
*/
public function get_authenticate_url() {
$url = $this
->create_url('oauth/authenticate', '');
if (!empty($this->token)) {
$url .= '?access_token=' . $this->token['access_token'];
}
return $url;
}
/**
* Requests token. Not implemented with Instagram yet.
*/
public function get_request_token() {
$url = $this
->create_url('oauth/request_token', '');
try {
$response = $this
->auth_request($url);
} catch (InstagramException $e) {
}
parse_str($response, $token);
$this->token = $token;
$this->access_token = $token['access_token'];
$this->auth_user = new InstagramUser($token['user']);
return $token;
}
/**
* Retrieves the access token.
*
* @param string $code
* @param string $redirect_uri
* @param string $grant_type
* @return type
*/
public function get_access_token($code, $redirect_uri, $grant_type = 'authorization_code') {
if ($this->access_token !== NULL) {
return $this->access_token;
}
$url = $this
->create_url('oauth/access_token', '');
$params = array(
'client_id' => $this->client_id,
'client_secret' => $this->client_secret,
'grant_type' => $grant_type,
'redirect_uri' => $redirect_uri,
'code' => $code,
);
try {
$response = $this
->auth_request($url, $params, 'POST', FALSE);
} catch (InstagramException $e) {
watchdog('drupagram OAuth', '!message', array(
'!message' => $e
->__toString(),
), WATCHDOG_ERROR);
return FALSE;
}
$token = json_decode($response, TRUE);
$this->token = $token;
$this->access_token = $token['access_token'];
$token['user']['oauth_token'] = $token['access_token'];
$this->auth_user = new InstagramUser($token['user']);
return $token;
}
public function auth_request($url, $params = array(), $method = 'POST', $use_auth = TRUE) {
return $this
->request($url, $params, $method, $use_auth);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Instagram:: |
protected | property | OAuth user object | |
Instagram:: |
protected | property | ||
Instagram:: |
protected | property | ||
Instagram:: |
protected | property | JSON encoded OAuth token | |
Instagram:: |
protected | property | ||
Instagram:: |
protected | property | ||
Instagram:: |
protected | property | ||
Instagram:: |
public | function | Method for calling any drupagram api resource | |
Instagram:: |
protected | function | ||
Instagram:: |
protected | function | Get an array of Instagram objects from an API endpoint | |
Instagram:: |
protected | function | ||
Instagram:: |
protected | function | Perform a request | |
Instagram:: |
constant | The name of the GET param that holds the authentication code | ||
Instagram:: |
public | function | See the authenticated user's feed. GET /users/self/feed | |
Instagram:: |
public | function | See the authenticated user's list of media they've liked. Note that this list is ordered by the order in which the user liked the media. Private media is returned as long as the authenticated user has permission to view that media. Liked… | |
Instagram:: |
public | function | Set the username and password | |
Instagram:: |
public | function | Get the most recent hash media published. GET v1/tags/!tag_name/media/recent | |
Instagram:: |
public | function | ||
Instagram:: |
public | function | Get the most recent media published by a user. GET /users/{user-id}/media/recent | |
Instagram:: |
public | function | Search for a user by name. GET /users/search | |
InstagramOAuth:: |
protected | property |
Decoded plain access token Overrides Instagram:: |
|
InstagramOAuth:: |
protected | property | ||
InstagramOAuth:: |
protected | property | ||
InstagramOAuth:: |
protected | property | ||
InstagramOAuth:: |
protected | property | ||
InstagramOAuth:: |
protected | property | ||
InstagramOAuth:: |
public | function |
Perform an authentication required request. Overrides Instagram:: |
|
InstagramOAuth:: |
public | function | Retrieves the access token. | |
InstagramOAuth:: |
public | function | Returns the properly formatted authentication url | |
InstagramOAuth:: |
public | function | Returns the properly formatted authorization url. | |
InstagramOAuth:: |
public | function | Requests token. Not implemented with Instagram yet. | |
InstagramOAuth:: |
public | function |
Constructor for the InstagramOAuth class Overrides Instagram:: |