InstagramScraper\Instagram::getAccount PHP Method

getAccount() public static method

public static getAccount ( $username )
    public static function getAccount($username)
    {
        $response = Request::get(Endpoints::getAccountJsonLink($username));
        if ($response->code === 404) {
            throw new InstagramNotFoundException('Account with given username does not exist.');
        }
        if ($response->code !== 200) {
            throw new InstagramException('Response code is ' . $response->code . '. Body: ' . $response->body . ' Something went wrong. Please report issue.');
        }
        $userArray = json_decode($response->raw_body, true);
        if (!isset($userArray['user'])) {
            throw new InstagramException('Account with this username does not exist');
        }
        return Account::fromAccountPage($userArray['user']);
    }

Usage Example

 public function testGetAccountByUsername()
 {
     $account = Instagram::getAccount('kevin');
     $this->assertEquals('kevin', $account->username);
     $this->assertEquals('3', $account->id);
 }