InstagramScraper\Instagram::getAccountById PHP Метод

getAccountById() публичный статический Метод

public static getAccountById ( $id )
    public static function getAccountById($id)
    {
        if (!is_numeric($id)) {
            throw new \InvalidArgumentException('User id must be integer or integer wrapped in string');
        }
        $parameters = Endpoints::getAccountJsonInfoLinkByAccountId($id);
        //        self::getContentsFromUrl($parameters);
        //        $response = Request::get(Endpoints::getAccountJsonInfoLinkByAccountId($id));
        //        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(self::getContentsFromUrl($parameters), true);
        if ($userArray['status'] === 'fail') {
            throw new InstagramException($userArray['message']);
        }
        if (!isset($userArray['username'])) {
            throw new InstagramNotFoundException('User with this id not found');
        }
        return Account::fromAccountPage($userArray);
    }

Usage Example

Пример #1
0
 public function testGetAccountById()
 {
     $account = Instagram::getAccountById(3);
     $this->assertEquals('kevin', $account->username);
     $this->assertEquals('3', $account->id);
 }