public function InstagramAccount::getToken in Instagram Feeds 8
Gets the Instagram long-lived token.
Parameters
string $client_id: Instagram app (client) ID.
string $client_secret: Instagram app (client) secret.
string $code: Instagram auth code to regenerate the token.
bool $save: Save entity or not after token has been refreshed successfully.
Return value
string Instagram long-lived access token for the authorized Instagram account.
Overrides InstagramAccountInterface::getToken
2 calls to InstagramAccount::getToken()
- InstagramAccount::getAccountName in src/
Entity/ InstagramAccount.php  - Gets Instagram account username.
 - InstagramAccount::refreshToken in src/
Entity/ InstagramAccount.php  - Tries to refresh long-lived Instagram access token.
 
File
- src/
Entity/ InstagramAccount.php, line 196  
Class
- InstagramAccount
 - Defines the instagram_account entity class.
 
Namespace
Drupal\instagram_feeds\EntityCode
public function getToken($client_id = '', $client_secret = '', $code = '', $save = FALSE) : string {
  // Refresh token in any case if $code exists.
  if (!empty($code) && !empty($client_id) && !empty($client_secret)) {
    try {
      $this
        ->setNewToken($client_id, $client_secret, $code, $save);
    } catch (\Exception $e) {
      \Drupal::messenger()
        ->addError($e
        ->getMessage());
    }
  }
  return $this
    ->tokenIsValid() ? $this
    ->get('token')
    ->first()
    ->getString() : '';
}